### PHP LangQuery Class Setup and Usage Source: https://github.com/enesnr/langquery/blob/master/README.md Demonstrates the basic setup and usage of the LangQuery PHP class. It covers one-line setup, automatic language detection and saving, echoing translations, and using parameters for dynamic content. The class supports .ini based language files. ```php include("LangQuery.php"); $L=new LangQuery(); // All Setup is ONLY ONE LINE // Browser language detected and loaded if available // Language will be autosaved and remembered next time. // Write Hello World echo($L('hello_world')); // Write Hello World Easier - In-line Echo Feature // You don't have to write echo. Just add '>' $L('>hello_world'); // Use in Strings echo("Hello Universe. {$L('hello_world')} Hello Europe"); // Write my age with parameter $L(">my_age",25); // Write my name and age with parameters $L(">my_name_age","Enes",25); // Using instant language change feature. // This will change language only for this line. $L(">[tr]hello")); ``` ```php

hello") ?>

[tr]hello")) ?>

my_text",25,"Jack Bauer") ?>

Change Language

``` ```php

{$L('hello')}

{$L('my_text',25,'Jack Bauer')}

Change Language

") ?> ``` ```php is_valid($_GET[Language])){ // Load Language $L->load($_GET[Language]); }else{ $default_language="en"; // Load $default_language but do not save to cookie. $L->load($default_language,FALSE); } ?>

hello") ?>

my_text",25,"Jack Bauer") ?>

Change Language

``` -------------------------------- ### INI Language File Example Source: https://github.com/enesnr/langquery/blob/master/README.md An example of a language file in .ini format used by the LangQuery class. It shows how to define key-value pairs for translations, including the use of placeholders for parameters. ```ini ; English Language hello = Hello World my_text = "I'm %s years old. My uncle is %s." ``` -------------------------------- ### Implement LangQuery in PHP and JavaScript Source: https://context7.com/enesnr/langquery/llms.txt This example demonstrates a full HTML integration using LangQuery. It shows how to initialize the library, render server-side translations, create a language switcher, and access translations within JavaScript functions. ```php <?php $L('>welcome'); ?>

hello'); ?>

my_info', 'John', 25); ?>

``` -------------------------------- ### Retrieve and Echo Translations Source: https://context7.com/enesnr/langquery/llms.txt Explains the use of the __invoke magic method to retrieve translations. Includes examples for direct echoing, parameter substitution, and temporary language switching. ```php $L = new LangQuery(); $text = $L('hello'); $L('>hello'); $L('>my_age', 25); $L('>my_info', 'John', 30); $L('>[tr]hello'); ``` -------------------------------- ### Initialize LangQuery Instance Source: https://context7.com/enesnr/langquery/llms.txt Demonstrates how to instantiate the LangQuery class in automatic or manual modes and configure library properties such as default language, cookie settings, and file paths. ```php include("langquery.php"); $L = new LangQuery(); $L = new LangQuery(FALSE); $L->default = "en"; $L->language_folder = "language"; $L->get_parameter = "Language"; $L->cookie_name = "Language"; $L->cookie_expire = 31536000; ``` -------------------------------- ### Explicitly Load Language Files Source: https://context7.com/enesnr/langquery/llms.txt Demonstrates the load() method for manual language switching, including options to persist the language preference via cookies. ```php $L = new LangQuery(FALSE); $L->load('de'); $L->load('tr', FALSE); if ($L->is_valid($_GET['Language'])) { $L->load($_GET['Language']); } ``` -------------------------------- ### PHP LangQuery Initialization and Usage Source: https://github.com/enesnr/langquery/blob/master/README.md Initializes the LangQuery class in PHP and demonstrates its usage for translating text. The library automatically handles language detection and saving preferences to a cookie. It's included via 'include("LangQuery.php");' and instantiated as '$L=new LangQuery();'. Translations are performed using the '$L(">text_key", ...)' method. ```php

hello") ?>

my_text",25,"Jack Bauer") ?>

Change Language

``` -------------------------------- ### Define Language INI Files Source: https://context7.com/enesnr/langquery/llms.txt Shows the structure of .ini files used by LangQuery. Keys represent translation IDs, and values support sprintf-style placeholders for dynamic content. ```ini ; language/en.ini hello = Hello World my_age = "I am %s years old." items_count = "You have %d items in your cart." ; language/de.ini hello = Hallo Welt my_age = "Ich bin %s Jahre alt." items_count = "Sie haben %d Artikel im Warenkorb." ``` -------------------------------- ### JavaScript LangQuery Usage Source: https://github.com/enesnr/langquery/blob/master/README.md Demonstrates how to use the LangQuery library within JavaScript for dynamic text translation. The library is loaded via a script tag pointing to 'langquery.php?js'. Translations are performed using the '$L("text_key", ...)' method, similar to its PHP counterpart, allowing for interactive elements like alerts. ```javascript alert($L('hello')) alert($L('my_text',25,'Jack Bauer')) ``` -------------------------------- ### Release Memory with free() Source: https://context7.com/enesnr/langquery/llms.txt The free() method clears language data from memory. It can be used to release specific languages or all loaded data, which is essential for memory optimization in long-running scripts. ```php $L = new LangQuery(); $L->load('en'); $L->free('en'); $L->free(); ``` -------------------------------- ### Detect Browser Language with browser() Source: https://context7.com/enesnr/langquery/llms.txt The browser() method extracts the user's preferred language from the HTTP_ACCEPT_LANGUAGE header. This is useful for automatically setting the application language based on the user's browser settings. ```php $L = new LangQuery(FALSE); $browser_lang = $L->browser(); if ($L->is_valid($L->browser())) { $L->load($L->browser()); } else { $L->load('en'); } ``` -------------------------------- ### Validate Language Code with is_valid() Source: https://context7.com/enesnr/langquery/llms.txt The is_valid() method verifies if a language code exists by checking for a corresponding .ini file. It is commonly used to validate user input before loading a language or to provide fallback mechanisms. ```php $L = new LangQuery(FALSE); if ($L->is_valid('fr')) { $L->load('fr'); } else { $L->load($L->default); } $requested_lang = $_GET['lang'] ?? 'en'; if ($L->is_valid($requested_lang)) { $L->load($requested_lang); } else { $L->load('en'); } ``` -------------------------------- ### Export Translations as JSON with json() Source: https://context7.com/enesnr/langquery/llms.txt The json() method returns all current translations as a JSON-encoded string. This is ideal for API responses or passing translation data to client-side applications. ```php $L = new LangQuery(); header('Content-Type: application/json'); echo $L->json(); ``` -------------------------------- ### Generate JavaScript Translation Helper with js() Source: https://context7.com/enesnr/langquery/llms.txt The js() method generates a script tag that provides a client-side $L() function. This allows developers to use the same translation syntax and sprintf formatting in JavaScript that is used in PHP. ```php ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.