Difference between revisions of "Creating a language definition file"

From Joomla! Documentation

m (Adjusted category)
(Marked this version for translation)
(19 intermediate revisions by 5 users not shown)
Line 1: Line 1:
Important note: Joomla language INI files must be saved as UTF-8 without the Byte Order Mark (BOM)<ref name="ftn2">For more information on Byte Order Mark see [http://unicode.org/faq/utf_bom.html#BOM http://unicode.org/faq/utf_bom.html#BOM]</ref>.
+
<noinclude><languages /></noinclude>
 +
{{Joomla version|version=3.x|comment=<translate><!--T:9-->
 +
series</translate>}}
 +
{{-}}
 +
{{notice|<translate><!--T:11-->
 +
The page [[S:MyLanguage/Specification of language files|Specification of language files]] contains some more details that should be '''verified''' - as it is no longer completely up-to-date - and then merged into this page.</translate>}}
  
The format of language definition files is very basic. Blanks lines and lines beginning with “#” are ignored and the latter may be used to add comments to the file. Each line consists of a pair of strings separated by an equals sign like this
+
<translate>
 +
<!--T:2-->
 +
Joomla! language definition files are written in the very basic ''[[wikipedia:INI file|INI file format]]''. They must be saved ''using the UTF-8 encoding''. Blank lines and lines beginning with <code>;</code> are ignored and the latter may be used to add comments to the file. Each line consists of a key-value pair separated by an equals sign like this:
 +
</translate>
  
KEY=Value
+
<source lang="ini">
 +
<translate><!--T:10-->
 +
KEY="value"
 +
</translate>
 +
</source>
  
where “''KEY''” is a string to be translated and “''Value''” is the translated string. For example
+
<translate>
 +
<!--T:3-->
 +
where <code>KEY</code> is a string to be translated and <code>value</code> is the translated string. For example:
 +
</translate>
  
ADDITIONAL INFORMATION=Additional Information
+
<source lang="ini">
 +
<translate><!--T:14-->
 +
ADDITIONAL_INFORMATION="Additional Information"</translate>
 +
</source>
  
The “''KEY''” must be in all capitals or the string will not be found. The case of the source string does not matter as strings are folded to upper case before searching takes place. So “additional information”, “Additional Information” or even “AdDiTiOnAl InFoRmAtIoN” will be matched.
+
<translate>
 +
<!--T:12-->
 +
Different versions of Joomla have used slightly different ways to read language files (namely a custom parser and the native PHP INI parser, the latter of which was buggy in PHP 5.2 and older), leading to different rules for what exactly is allowed in keys and values. Language files that abide by the following rules should work under many versions of Joomla, but at least under Joomla {{jver|3.x}} and newer.
 +
</translate>
  
The “''KEY''” can include spaces and other punctuation characters but there should not be any spaces either side of the equals sign as spaces are significant. If more than one entry has the same left-hand side, the last one to be encountered is the one that will be used.
+
<translate>
 +
<!--T:5-->
 +
The <code>KEY</code> should only use ASCII characters. It should only contain capital letters, digits, underscores and hyphens, and it should start with a capital letter. (Dots (<code>.</code>) are formally allowed, but do not appear to be completely supported.) It is a convention to replace any whitespace in the string to be translated with underscores. If more than one entry has the same key, the last one to be encountered is the one that will be used. When you use the key in a <code>JText::_</code> call, the case does not matter as strings are folded to upper case before searching takes place. So <code>additional_information</code>, <code>Additional_Information</code> or even <code>AdDiTiOnAl_InFoRmAtIoN</code> will be matched.
 +
</translate>
  
The "''VALUE''" cannot include double-quote characters ("). To get a double-quote character you must use the HTML special character sequence "&amp;quot;" instead. Single-quote characters (') are valid.
+
<translate>
 +
<!--T:6-->
 +
The <code>value</code> should always be surrounded by double-quote characters (<code>"</code>), as in the example. The value itself cannot include double-quote characters (<code>"</code>), although single-quote characters (<code>'</code>) are valid. Use <code>"_QQ_"</code>, ''including the double quotes'', to place a double-quote character in your value. For example, to attach the value <code><nowiki><span class="red">Warning!</span></nowiki></code> to the key <code>WARNING_TEXT</code>, use following line:
 +
</translate>
 +
 
 +
<source lang="ini">
 +
WARNING_TEXT="<span class="_QQ_"red"_QQ_">Warning!</span>"
 +
</source>
 +
 
 +
<translate>
 +
<!--T:13-->
 +
Note that these rules are stricter than required by [http://php.net/manual/en/function.parse-ini-file.php the PHP INI parser]. For example, the PHP INI parser allows you to omit the double quotes around the value as long as it does not contain certain characters. Using the rules above should make it much easier to avoid mistakes like forgetting double quotes when they ''are'' required.
 +
</translate>
 +
 
 +
<translate>
 +
<!--T:7-->
 +
Information about the changes in the language file format between the Joomla 1.5, 2.5 and 3.x series can be found on the page [[S:MyLanguage/Specification of language files|Specification of language files]].
 +
</translate>
  
More information about the discussed changed for Joomla 1.6 can be found on the page [[Specification of language files]] {{JVer|1.6}}
 
 
<noinclude>
 
<noinclude>
 
----
 
----
<references/>[[Category:Tutorials]][[Category:Language Development]]</noinclude>
+
<references/>
 +
<translate>
 +
<!--T:8-->
 +
[[Category:Tutorials]]
 +
[[Category:Language Development]]
 +
</translate>
 +
</noinclude>

Revision as of 09:25, 18 September 2015

Other languages:
Deutsch • ‎English • ‎Nederlands • ‎español • ‎français • ‎português • ‎русский
Joomla! 
3.x
series
Info non-talk.png
General Information

The page Specification of language files contains some more details that should be verified - as it is no longer completely up-to-date - and then merged into this page.

Joomla! language definition files are written in the very basic INI file format. They must be saved using the UTF-8 encoding. Blank lines and lines beginning with ; are ignored and the latter may be used to add comments to the file. Each line consists of a key-value pair separated by an equals sign like this:

KEY="value"

where KEY is a string to be translated and value is the translated string. For example:

ADDITIONAL_INFORMATION="Additional Information"

Different versions of Joomla have used slightly different ways to read language files (namely a custom parser and the native PHP INI parser, the latter of which was buggy in PHP 5.2 and older), leading to different rules for what exactly is allowed in keys and values. Language files that abide by the following rules should work under many versions of Joomla, but at least under Joomla Joomla 3.x and newer.

The KEY should only use ASCII characters. It should only contain capital letters, digits, underscores and hyphens, and it should start with a capital letter. (Dots (.) are formally allowed, but do not appear to be completely supported.) It is a convention to replace any whitespace in the string to be translated with underscores. If more than one entry has the same key, the last one to be encountered is the one that will be used. When you use the key in a JText::_ call, the case does not matter as strings are folded to upper case before searching takes place. So additional_information, Additional_Information or even AdDiTiOnAl_InFoRmAtIoN will be matched.

The value should always be surrounded by double-quote characters ("), as in the example. The value itself cannot include double-quote characters ("), although single-quote characters (') are valid. Use "_QQ_", including the double quotes, to place a double-quote character in your value. For example, to attach the value <span class="red">Warning!</span> to the key WARNING_TEXT, use following line:

WARNING_TEXT="<span class="_QQ_"red"_QQ_">Warning!</span>"

Note that these rules are stricter than required by the PHP INI parser. For example, the PHP INI parser allows you to omit the double quotes around the value as long as it does not contain certain characters. Using the rules above should make it much easier to avoid mistakes like forgetting double quotes when they are required.

Information about the changes in the language file format between the Joomla 1.5, 2.5 and 3.x series can be found on the page Specification of language files.