Language variables stand as a cornerstone for the internationalization and localization of Venddor IO, its modules, and affiliated solutions. Rather than placing texts in varied languages directly into PHP or template files, a specialized function is summoned. This function accepts a language variable's name, then returns the text in a language based on user preferences.
For a deep dive into leveraging language variables in modules, refer to our dedicated article.
Venddor IO, its modules, and the entire ecosystem rely on PO files (portable object) for translations. Every language has its dedicated PO file, containing language variable values.
PO is not unique to Venddor IO; it's an industry standard. Services related to localization, such as Crowdin, often interact with PO files. Dive deeper into PO files by exploring the GNU project's resources.
Within your Venddor IO installation, you'll find PO files nestled under the var/langs directory, which can be edited through specialized software or even basic text editors.
Here's a sample language variable in the English PO file:
msgctxt "Languages::email_marketing.subscription_confirmed"
msgid "Thank you for subscribing to our newsletter"
msgstr "Thank you for subscribing to our newsletter"
For the French rendition:
msgctxt "Languages::email_marketing.subscription_confirmed"
msgid "Thank you for subscribing to our newsletter"
msgstr "Merci de votre inscription à notre newsletter"
In the PO files, msgctxt identifies language variables as they appear in Smarty templates and PHP code (sans prefixes). As language variables can encompass translations of strings, module titles, settings, etc., diverse prefixes are used to distinguish them. Within PHP or TPL files, always commence language variable names with the Languages:: prefix. While invoking the translation function, exclude the prefixes.
Each language variable's name needs to be unique, and it's advised to include the module's name at the onset of msgctxt.
Sometimes, dynamic data, like product titles or hyperlinks, might need to be integrated with language variables. This is executed using placeholders, enclosed in square brackets. For instance:
msgctxt "Languages::admin_text_letter_footer"
msgid "E-shop of [company_name]."
msgstr "E-shop of [company_name]."
The placeholders can be replaced accordingly in Smarty templates.
Languages often differentiate between singular and plural wordings. To integrate these variants in language variables, utilize the | symbol and the [n] placeholder, as illustrated:
msgctxt "Languages::n_days"
msgid "[n] day|[n] days"
msgstr "[n] day|[n] days"
In PHP, the __ function is harnessed to retrieve a language variable's value:
$confirmed_text = __('email_marketing.subscription_confirmed');
fn_set_notification('I',$confirmed_text, $msg);
To weave a language variable into a Smarty template, employ the __ function:
{__("hello")}
Language variables with placeholders or multiple forms can be infused into templates or code, and the appropriate form or placeholder is selected based on context.
Language variables can be modified via:
In sum, Venddor IO's structured approach to language variables ensures a seamless internationalization experience for its users.