Click here to go back to the previous section: Adding User Preferences
Please note that this documentation relates to Vanilla 1
It is highly recommended that when writing extensions you don’t hard-code text any definitions, message strings etc., but use “SetDefinition” to define them and “GetDefinition” to retrieve them. This means your extension can be ported to any language out there.
You can use the Context Object’s “SetDefinition” method to define any standard definition-strings you create while writing your extensions at the top of your extension file:
$Context->SetDefinition('UniqueDefinitionName', 'The text string for the definition');
In your code, then use the Context Object’s “GetDefinition” method to retrieve the definition from the language dictionary where you would normally write the message, e.g.:
... $Context->GetDefinition("UniqueDefinitionName") ...
New definitions for your extensions can be added manually to the conf/language.php file by people who need translations of your definitions or wish to use a different wording. They do not need to edit your add-on, avoiding the introduction of errors and making it easier for them to update them without losing their language definitions.
Note: this method should be used instead of the old $Context→Dictionary[”UniqueDefinitionName”] = “Text message”;
Add your translations of text-definitions in extensions to the conf/language.php file in the following form:
$Context->Dictionary["UniqueDefinitionName"] = "My translation of original string";
The “UniqueDefinitionName” should exactly match the name used in the extension. This will override the message provided in the extension as well as any message that may be defined in the languages/your_language/definitions.php file. By placing your definitions in the conf/language.php you can update add-ons, vanilla and language definitions without your translations being overwritten.
Note: If your translation does not appear, it may be that the extension author has not defined the definitions using “SetDefinition” but the old “Dictionary” method. Contact the add-on author and refer to this page so that the add-on can be updated for everyone. A quick fix is to comment out the definitions in the author’s extension. See the revision history for this wiki article for further details on the old method.
Click here to read the next section on developing new extensions: Creating Custom Controls