J3.x

Difference between revisions of "Developing an MVC Component/Adding language management"

From Joomla! Documentation

< J3.x:Developing an MVC Component
(Marked this version for translation)
(7 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{:J3.1:Developing a MVC Component}}
+
<noinclude><languages /></noinclude>
 
+
{{:J3.1:Developing a MVC Component/<translate><!--T:1-->
 +
en</translate>}}
 
{{review}}
 
{{review}}
 
+
<translate>== Introduction == <!--T:2--></translate>
This is a multiple-article series of tutorials on how to develop a Model-View-Contoller [[Component]] for Joomla! Version {{JVer|{{CurrentSTSVer|minor}}}}.
+
<translate><!--T:3-->
 
+
This tutorial is part of the [[S:MyLanguage/J3.2:Developing a MVC Component | Developing a MVC Component for Joomla! 3.2]] tutorial. You are encouraged to read the previous parts of the tutorial before reading this.</translate>
== Introduction ==
+
<translate><!--T:4-->
This tutorial is part of the [[J3.2:Developing a MVC Component | Developing a MVC Component for Joomla! 3.2]] tutorial. You are encouraged to read the previous parts of the tutorial before reading this.
+
Joomla! 3.2 manages languages for components in four different situations:</translate>
 
+
<translate><!--T:5-->
Joomla!3.2 manages languages for components in four different situations:
 
 
* displaying a component in the public site
 
* displaying a component in the public site
 
* managing a component in the backend
 
* managing a component in the backend
 
* managing menus in the backend
 
* managing menus in the backend
* installing a component
+
* installing a component</translate>
  
Joomla!3.2 uses two different location folder for languages:
+
<translate><!--T:6-->
* one in ''administrator/language'' or ''language''
+
Joomla! 3.2 uses two different location folder for languages:</translate>
* one in the component folder (''administrator/components/*component*/language'' or ''components/*component*/language'')
+
<translate><!--T:7-->
 +
* one in <tt>administrator/language</tt> or <tt>language</tt></translate>
 +
<translate><!--T:8-->
 +
* one in the component folder (<tt>administrator/components/*component*/language</tt> or <tt>components/*component*/language</tt>)</translate>
  
It depends how the component is installed.
+
<translate><!--T:9-->
 +
It depends how the component is installed.</translate>
  
== Adding language translation in the public site ==
+
<translate>== Adding language translation in the public site == <!--T:10--></translate>
With your favorite file manager and editor, put a file ''site/language/en-GB/en-GB.com_helloworld.ini''. This file will contain translation for the public part. For the moment, this file is empty
+
<translate><!--T:11-->
 +
With your favorite file manager and editor, put a file <tt>site/language/en-GB/en-GB.com_helloworld.ini</tt>. This file will contain translation for the public part. For the moment, this file is empty.</translate>
  
 
<span id="site/language/en-GB/en-GB.com_helloworld.ini">
 
<span id="site/language/en-GB/en-GB.com_helloworld.ini">
''site/language/en-GB/en-GB.com_helloworld.ini''
+
<tt>site/language/en-GB/en-GB.com_helloworld.ini</tt>
 
<source lang="ini">
 
<source lang="ini">
 
</source>
 
</source>
 
</span>
 
</span>
  
For the moment, there are no translations strings in this file.
+
<translate><!--T:12-->
 +
For the moment, there are no translations strings in this file.</translate>
  
== Adding language translation when managing the component ==
+
<translate>== Adding language translation when managing the component == <!--T:13--></translate>
With your favorite file manager and editor, put a file ''admin/language/en-GB/en-GB.com_helloworld.ini''. This file will contain translation for the backend part.
+
<translate><!--T:14-->
 +
With your favorite file manager and editor, put a file <tt>admin/language/en-GB/en-GB.com_helloworld.ini</tt>. This file will contain translation for the backend part.</translate>
  
 
<span id="admin/language/en-GB/en-GB.com_helloworld.ini">
 
<span id="admin/language/en-GB/en-GB.com_helloworld.ini">
''admin/language/en-GB/en-GB.com_helloworld.ini''
+
<tt>admin/language/en-GB/en-GB.com_helloworld.ini</tt>
 
<source lang="ini">
 
<source lang="ini">
 +
; Joomla! Project
 +
; Copyright (C) 2005 - 2015 Open Source Matters. All rights reserved.
 +
; License GNU General Public License version 2 or later; see LICENSE.txt, see LICENSE.php
 +
; Note : All ini files need to be saved as UTF-8
 +
 +
COM_HELLOWORLD_NUM="#"
 +
COM_HELLOWORLD_PUBLISHED="Published"
 +
COM_HELLOWORLD_HELLOWORLDS_NAME="Name"
 +
COM_HELLOWORLD_ID="Id"
 +
 
COM_HELLOWORLD_HELLOWORLD_FIELD_GREETING_DESC="This message will be displayed"
 
COM_HELLOWORLD_HELLOWORLD_FIELD_GREETING_DESC="This message will be displayed"
 
COM_HELLOWORLD_HELLOWORLD_FIELD_GREETING_LABEL="Message"
 
COM_HELLOWORLD_HELLOWORLD_FIELD_GREETING_LABEL="Message"
 
COM_HELLOWORLD_HELLOWORLD_HEADING_GREETING="Greeting"
 
COM_HELLOWORLD_HELLOWORLD_HEADING_GREETING="Greeting"
 
COM_HELLOWORLD_HELLOWORLD_HEADING_ID="Id"
 
COM_HELLOWORLD_HELLOWORLD_HEADING_ID="Id"
 +
 
</source>
 
</source>
 
</span>
 
</span>
  
== Adding language translation when managing the menus in the backend ==
+
<translate>== Adding language translation when managing the menus in the backend == <!--T:15--></translate>
With your favorite file manager and editor, put a file ''admin/language/en-GB/en-GB.com_helloworld.sys.ini''. This file will contain translation for the backend part.
+
<translate><!--T:16-->
 +
With your favorite file manager and editor, put a file <tt>admin/language/en-GB/en-GB.com_helloworld.sys.ini</tt>. This file will contain translation for the backend part.</translate>
  
 
<span id="admin/language/en-GB/en-GB.com_helloworld.sys.ini">
 
<span id="admin/language/en-GB/en-GB.com_helloworld.sys.ini">
''admin/language/en-GB/en-GB.com_helloworld.sys.ini''
+
<tt>admin/language/en-GB/en-GB.com_helloworld.sys.ini</tt>
 
<source lang="ini">
 
<source lang="ini">
 +
; Joomla! Project
 +
; Copyright (C) 2005 - 2015 Open Source Matters. All rights reserved.
 +
; License GNU General Public License version 2 or later; see LICENSE.txt, see LICENSE.php
 +
; Note : All ini files need to be saved as UTF-8
 +
 
COM_HELLOWORLD="Hello World!"
 
COM_HELLOWORLD="Hello World!"
 
COM_HELLOWORLD_DESCRIPTION="This is the Hello World description"
 
COM_HELLOWORLD_DESCRIPTION="This is the Hello World description"
Line 55: Line 79:
 
COM_HELLOWORLD_HELLOWORLD_VIEW_DEFAULT_DESC="This view displays a selected message"
 
COM_HELLOWORLD_HELLOWORLD_VIEW_DEFAULT_DESC="This view displays a selected message"
 
COM_HELLOWORLD_MENU="Hello World!"
 
COM_HELLOWORLD_MENU="Hello World!"
 +
 
</source>
 
</source>
 
</span>
 
</span>
  
== Language File Location Options ==
+
<translate>== Language File Location Options == <!--T:17--></translate>
Starting with version 1.7 there are 2 ways to install language files for an extension.
+
<translate><!--T:18-->
One can use one or the other or a combination of both.
+
Starting with version 1.7 there are 2 ways to install language files for an extension. One can use one or the other or a combination of both.</translate>
 +
 
 +
<translate><!--T:19-->
 +
The 1.5 way will install the files in the CORE language folders (<tt>ROOT/administrator/language/</tt> and <tt>ROOT/language/</tt>).
 +
Since version 1.6, include the files in a "language" folder installed at the root of the extension.</translate>
 +
 
 +
<translate><!--T:20-->
 +
Therefore an extension can include a language folder with a .sys.ini different from the one installed in the Joomla core language folders. (This last one not being included in that language folder but in root or any other folder not installed.)</translate>
  
The 1.5 way will install the files in the CORE language folders (ROOT/administrator/language/ and ROOT/language/ ).
+
<translate><!--T:21-->
Since 1.6— includes the files in a "language" folder installed at the root of the extension.
+
This lets us display 2 different descriptions: one from the sys.ini in the "language" folder is used as a message displayed when installation is finished, the other (from the .ini) is used for "normal" operation, that is, when the extension is edited in the back-end. This can be extremely useful when the installation also uses some scripts and requires a different value for the description.</translate>
  
Therefore an extension can include a language folder with a .sys.ini different from the one installed in joomla core language folders (this last one not being included in that language folder but in root or any other folder not installed).
+
{{tip|<translate><!--T:22-->
This let's display 2 different descriptions: one from the sys.ini in the "language" folder is used as a message displayed when install has been done, the other (from the .ini) is used for "normal" operation, i.e. when the extension is edited in back-end.
+
The sys.ini file is also used to translate the name of the extensions in some back-end Managers and to provide menu translation for components.</translate>|title=<translate><!--T:23-->
This can be extremely useful when installing also uses some scripts and requires a different value for the description.
+
You Should Note!</translate>}}
  
{{tip|The sys.ini file is also used to translate the name of the extensions in some back-end Managers and to provide menu translation for components.|title=You Should Note!}}
+
<translate><!--T:24-->
 +
Therefore, the xml would include since 1.6:</translate>
  
Therefore, the xml would include since 1.6
 
 
<source lang="xml">
 
<source lang="xml">
 
<files>
 
<files>
Line 90: Line 122:
 
</source>
 
</source>
  
and/or then (1.5 way):
+
<translate><!--T:25-->
 +
and/or then (1.5 way):</translate>
 +
 
 
<source lang="xml">
 
<source lang="xml">
<languages folder="joomlacorelanguagefolders"> // if using another language folder for cleanliness (any folder name will fit)
+
<languages folder="joomlacorelanguagefolders"> // If using another language folder for cleanliness. (Any folder name will fit.)
 
<language tag="en-GB">en-GB/en-GB.whatever.ini</language> // or
 
<language tag="en-GB">en-GB/en-GB.whatever.ini</language> // or
 
<language tag="en-GB">en-GB.whatever.ini</language> if no tagged subfolder
 
<language tag="en-GB">en-GB.whatever.ini</language> if no tagged subfolder
Line 100: Line 134:
 
</source>
 
</source>
  
or simply in ROOT
+
<translate><!--T:26-->
 +
or simply in ROOT:</translate>
 +
 
 
<source lang="xml">
 
<source lang="xml">
 
<languages>
 
<languages>
Line 108: Line 144:
 
</source>
 
</source>
  
Language file used by the install script during install of a component(''the first install'' not upgrade) obeys specific rules described in the article, [[Specification of language files]]. During the first install, only the language file included in the component folder <code>(/administrator/components/com_helloworld/language)</code> is used when present. If this file is only provided in the CORE language folder <code>(/administrator/language)</code>, no translation occurs. This also applies to KEYs used in the manifest file.
+
<translate><!--T:27-->
 +
Language file used by the installation script during the installation of a component(''the first install'', not an upgrade) obeys specific rules described in the article, [[S:MyLanguage/Specification of language files|Specification of language files]]. During the first installation, only the language file included in the component folder <code>(/administrator/components/com_helloworld/language)</code> is used when present. If this file is only provided in the CORE language folder <code>(/administrator/language)</code>, no translation occurs. This also applies to KEYs used in the manifest file.</translate>
  
When upgrading or uninstalling the extension (not installing), it is the sys.ini file present in the extension root language folder which will display the result of the install from the description key/value. Thereafter, if present, the sys.ini as well as the ini installed in CORE language folder will have priority over the files present in the root language folder of the extension.
+
<translate><!--T:28-->
 +
When upgrading or uninstalling the extension (not installing), it is the sys.ini file present in the extension root language folder which will display the result of the installation from the description key/value. Thereafter, if present, the sys.ini as well as the .ini installed in the CORE language folder will have priority over the files present in the root language folder of the extension.</translate>
  
{{tip|title=Advantages of Extension "Language" Folder|''One advantage of installing the files in the extension "language" folder is that these '''are not touched when updating''' a language pack.''{{-}}The other advantage is that this folder can include multiple languages (en-GB always, fr-FR, it-IT, etc.) not requiring the user to install the corresponding language pack. This is handy as they are available if, later on, a user installs the corresponding pack.}}
+
{{tip|title=<translate><!--T:29-->
 +
Advantages of Extension "Language" Folder</translate>|<translate><!--T:30-->
 +
''One advantage of installing the files in the extension "language" folder is that these '''are not touched when updating''' a language pack.''{{-}}The other advantage is that this folder can include multiple languages (en-GB always, fr-FR, it-IT, etc.) not requiring the user to install the corresponding language pack. This is handy as they are available if, later on, a user installs the corresponding pack.</translate>}}
  
== Packaging the component ==
+
<translate>== Packaging the component == <!--T:31--></translate>
  
Content of your code directory
+
<translate><!--T:32-->
 +
Content of your code directory</translate>
 
* ''[[#helloworld.xml|helloworld.xml]]''
 
* ''[[#helloworld.xml|helloworld.xml]]''
* ''[[J3.2:Developing_a_MVC_Component/Adding_a_view_to_the_site_part#site/helloworld.php|site/helloworld.php]]''
+
* ''[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Adding_a_view_to_the_site_part#site/helloworld.php|site/helloworld.php]]''
* ''[[J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|site/index.html]]''
+
* ''[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|site/index.html]]''
* ''[[J3.2:Developing_a_MVC_Component/Adding_a_view_to_the_site_part#site/controller.php|site/controller.php]]''
+
* ''[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Adding_a_view_to_the_site_part#site/controller.php|site/controller.php]]''
* ''[[J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|site/views/index.html]]''
+
* ''[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|site/views/index.html]]''
* ''[[J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|site/views/helloworld/index.html]]''
+
* ''[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|site/views/helloworld/index.html]]''
* ''[[J3.2:Developing_a_MVC_Component/Adding_a_view_to_the_site_part#site/views/helloworld/view.html.php|site/views/helloworld/view.html.php]]''
+
* ''[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Adding_a_view_to_the_site_part#site/views/helloworld/view.html.php|site/views/helloworld/view.html.php]]''
* ''[[J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|site/views/helloworld/tmpl/index.html]]''
+
* ''[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|site/views/helloworld/tmpl/index.html]]''
* ''[[J3.2:Developing_a_MVC_Component/Using_the_database#site/views/helloworld/tmpl/default.xml|site/views/helloworld/tmpl/default.xml]]''
+
* ''[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Using_the_database#site/views/helloworld/tmpl/default.xml|site/views/helloworld/tmpl/default.xml]]''
* ''[[J3.2:Developing_a_MVC_Component/Adding_a_view_to_the_site_part#site/views/helloworld/tmpl/default.php|site/views/helloworld/tmpl/default.php]]''
+
* ''[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Adding_a_view_to_the_site_part#site/views/helloworld/tmpl/default.php|site/views/helloworld/tmpl/default.php]]''
* ''[[J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|site/models/index.html]]''
+
* ''[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|site/models/index.html]]''
* ''[[J3.2:Developing_a_MVC_Component/Using_the_database#site/models/helloworld.php|site/models/helloworld.php]]''
+
* ''[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Using_the_database#site/models/helloworld.php|site/models/helloworld.php]]''
* ''[[J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|site/language/index.html]]''
+
* ''[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|site/language/index.html]]''
* ''[[J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|site/language/en-GB/index.html]]''
+
* ''[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|site/language/en-GB/index.html]]''
 
* ''[[#site/language/en-GB/en-GB.com_helloworld.ini|site/language/en-GB/en-GB.com_helloworld.ini]]''
 
* ''[[#site/language/en-GB/en-GB.com_helloworld.ini|site/language/en-GB/en-GB.com_helloworld.ini]]''
* ''[[J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|admin/index.html]]''
+
* ''[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|admin/index.html]]''
* ''[[J3.2:Developing_a_MVC_Component/Basic_backend#admin/helloworld.php|admin/helloworld.php]]''
+
* ''[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Basic_backend#admin/helloworld.php|admin/helloworld.php]]''
* ''[[J3.2:Developing_a_MVC_Component/Basic_backend#admin/controller.php|admin/controller.php]]''
+
* ''[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Basic_backend#admin/controller.php|admin/controller.php]]''
* ''[[J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|admin/sql/index.html]]''
+
* ''[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|admin/sql/index.html]]''
* ''[[J3.2:Developing_a_MVC_Component/Using_the_database#admin/sql/install.mysql.utf8.sql|admin/sql/install.mysql.utf8.sql]]''
+
* ''[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Using_the_database#admin/sql/install.mysql.utf8.sql|admin/sql/install.mysql.utf8.sql]]''
* ''[[J3.2:Developing_a_MVC_Component/Using_the_database#admin/sql/uninstall.mysql.utf8.sql|admin/sql/uninstall.mysql.utf8.sql]]''
+
* ''[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Using_the_database#admin/sql/uninstall.mysql.utf8.sql|admin/sql/uninstall.mysql.utf8.sql]]''
* ''[[J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|admin/sql/updates/index.html]]''
+
* ''[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|admin/sql/updates/index.html]]''
* ''[[J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|admin/sql/updates/mysql/index.html]]''
+
* ''[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|admin/sql/updates/mysql/index.html]]''
* ''[[J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#admin/sql/updates/mysql/0.0.1.sql|admin/sql/updates/mysql/0.0.1.sql]]''
+
* ''[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#admin/sql/updates/mysql/0.0.1.sql|admin/sql/updates/mysql/0.0.1.sql]]''
* ''[[J3.2:Developing_a_MVC_Component/Using_the_database#admin/sql/install.mysql.utf8.sql|admin/sql/updates/mysql/0.0.6.sql]]''
+
* ''[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Using_the_database#admin/sql/install.mysql.utf8.sql|admin/sql/updates/mysql/0.0.6.sql]]''
* ''[[J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|admin/models/index.html]]''
+
* ''[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|admin/models/index.html]]''
* ''[[J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|admin/models/fields/index.html]]''
+
* ''[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|admin/models/fields/index.html]]''
* ''[[J3.2:Developing_a_MVC_Component/Using_the_database#admin/models/fields/helloworld.php|admin/models/fields/helloworld.php]]''
+
* ''[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Using_the_database#admin/models/fields/helloworld.php|admin/models/fields/helloworld.php]]''
* ''[[J3.2:Developing_a_MVC_Component/Basic_backend#admin/models/helloworlds.php|admin/models/helloworlds.php]]''
+
* ''[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Basic_backend#admin/models/helloworlds.php|admin/models/helloworlds.php]]''
* ''[[J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|admin/views/index.html]]''
+
* ''[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|admin/views/index.html]]''
* ''[[J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|admin/views/helloworlds/index.html]]''
+
* ''[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|admin/views/helloworlds/index.html]]''
* ''[[J3.2:Developing_a_MVC_Component/Basic_backend#admin/views/helloworlds/view.html.php|admin/views/helloworlds/view.html.php]]''
+
* ''[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Basic_backend#admin/views/helloworlds/view.html.php|admin/views/helloworlds/view.html.php]]''
* ''[[J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|admin/views/helloworlds/tmpl/index.html]]''
+
* ''[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|admin/views/helloworlds/tmpl/index.html]]''
* ''[[J3.2:Developing_a_MVC_Component/Basic_backend#admin/views/helloworlds/tmpl/default.php|admin/views/helloworlds/tmpl/default.php]]''
+
* ''[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Basic_backend#admin/views/helloworlds/tmpl/default.php|admin/views/helloworlds/tmpl/default.php]]''
* ''[[J3.2:Developing_a_MVC_Component/Basic_backend#admin/views/helloworlds/tmpl/default_head.php|admin/views/helloworlds/tmpl/default_head.php]]''
+
* ''[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|admin/tables/index.html]]''
* ''[[J3.2:Developing_a_MVC_Component/Basic_backend#admin/views/helloworlds/tmpl/default_body.php|admin/views/helloworlds/tmpl/default_body.php]]''
+
* ''[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Using_the_database#admin/tables/helloworld.php|admin/tables/helloworld.php]]''
* ''[[J3.2:Developing_a_MVC_Component/Basic_backend#admin/views/helloworlds/tmpl/default_foot.php|admin/views/helloworlds/tmpl/default_foot.php]]''
+
* ''[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|admin/language/index.html]]''
* ''[[J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|admin/tables/index.html]]''
 
* ''[[J3.2:Developing_a_MVC_Component/Using_the_database#admin/tables/helloworld.php|admin/tables/helloworld.php]]''
 
 
* ''[[#admin/language/en-GB/en-GB.com_helloworld.ini|admin/language/en-GB/en-GB.com_helloworld.ini]]''
 
* ''[[#admin/language/en-GB/en-GB.com_helloworld.ini|admin/language/en-GB/en-GB.com_helloworld.ini]]''
 
* ''[[#admin/language/en-GB/en-GB.com_helloworld.sys.ini|admin/language/en-GB/en-GB.com_helloworld.sys.ini]]''
 
* ''[[#admin/language/en-GB/en-GB.com_helloworld.sys.ini|admin/language/en-GB/en-GB.com_helloworld.sys.ini]]''
* ''[[#language/en-GB/en-GB.com_helloworld.sys.ini|language/en-GB/en-GB.com_helloworld.sys.ini]]''
+
* ''[[S:MyLanguage/J3.2:Developing_a_MVC_Component/Developing_a_Basic_Component#index.html|admin/language/en-GB/index.html]]''
  
Create a compressed file of this directory or directly download the [https://github.com/joomla/Joomla-3.2-Hello-World-Component/archive/step-8-adding-language-management.zip archive] and install it using the extension manager of Joomla. You can add a menu item of this component using the menu manager in the backend.
+
<translate><!--T:33-->
 +
Create a compressed file of this directory or directly download the [https://github.com/scionescire/Joomla-3.2-Hello-World-Component/archive/step-8-adding-language-management.zip archive] and install it using the extension manager of Joomla. You can add a menu item of this component using the menu manager in the backend.</translate>
  
 
<span id="helloworld.xml">
 
<span id="helloworld.xml">
''helloworld.xml''
+
<tt>helloworld.xml</tt>
<source lang="xml">
+
<source lang="xml" highlight="4,13,15,45-47,51,70-73">
 
<?xml version="1.0" encoding="utf-8"?>
 
<?xml version="1.0" encoding="utf-8"?>
<extension type="component" version="3.2" method="upgrade">
+
<extension type="component" version="3.2.0" method="upgrade">
+
 
 
<name>COM_HELLOWORLD</name>
 
<name>COM_HELLOWORLD</name>
 
<!-- The following elements are optional and free of formatting constraints -->
 
<!-- The following elements are optional and free of formatting constraints -->
Line 179: Line 219:
 
<version>0.0.8</version>
 
<version>0.0.8</version>
 
<!-- The description is optional and defaults to the name -->
 
<!-- The description is optional and defaults to the name -->
<description>COM_HELLOWORLD_DESCRIPTION</description>
+
<description>COM_HELLOWORLD_DESCRIPTION</description>
+
 
<install> <!-- Runs on install -->
+
<install> <!-- Runs on install -->
 
<sql>
 
<sql>
 
<file driver="mysql" charset="utf8">sql/install.mysql.utf8.sql</file>
 
<file driver="mysql" charset="utf8">sql/install.mysql.utf8.sql</file>
Line 193: Line 233:
 
<update> <!-- Runs on update; New since J2.5 -->
 
<update> <!-- Runs on update; New since J2.5 -->
 
<schemas>
 
<schemas>
<schemapath type="mysql">sql/updates/mysql/</schemapath>
+
<schemapath type="mysql">sql/updates/mysql</schemapath>
 
</schemas>
 
</schemas>
 
</update>
 
</update>
+
 
 
<!-- Site Main File Copy Section -->
 
<!-- Site Main File Copy Section -->
 
<!-- Note the folder attribute: This attribute describes the folder
 
<!-- Note the folder attribute: This attribute describes the folder
Line 207: Line 247:
 
<folder>views</folder>
 
<folder>views</folder>
 
<folder>models</folder>
 
<folder>models</folder>
<folder>language</folder>
 
 
</files>
 
</files>
+
 
 +
        <languages folder="site/language">
 +
<language tag="en-GB">en-GB/en-GB.com_helloworld.ini</language>
 +
        </languages>
 +
 
 
<administration>
 
<administration>
 
<!-- Administration Menu Section -->
 
<!-- Administration Menu Section -->
<menu>COM_HELLOWORLD_MENU</menu>
+
<menu link='index.php?option=com_helloworld'>COM_HELLOWORLD_MENU</menu>
 
<!-- Administration Main File Copy Section -->
 
<!-- Administration Main File Copy Section -->
 
<!-- Note the folder attribute: This attribute describes the folder
 
<!-- Note the folder attribute: This attribute describes the folder
Line 230: Line 273:
 
<!-- views files section -->
 
<!-- views files section -->
 
<folder>views</folder>
 
<folder>views</folder>
<!-- admin languages files section -->
 
            <folder>language</folder>
 
 
</files>
 
</files>
 +
<languages folder="admin/language">
 +
        <language tag="en-GB">en-GB/en-GB.com_helloworld.ini</language>
 +
                        <language tag="en-GB">en-GB/en-GB.com_helloworld.sys.ini</language>
 +
</languages>
 
</administration>
 
</administration>
+
 
 
</extension>
 
</extension>
 
</source>
 
</source>
 
</span>
 
</span>
  
In this ''helloworld.xml'' file, languages are installed in:
+
<translate><!--T:34-->
* ''administrator/language'' for the admin part (look at the xml languages tag)
+
In this <tt>helloworld.xml</tt> file, languages are installed in:</translate>
* ''components/com_helloworld/language'' for the site part (there are no xml languages tag in the site part of the xml description file, but the language folder is included)
+
<translate><!--T:35-->
 +
* <tt>administrator/language</tt> for the admin part (look at the xml languages tag).</translate>
 +
<translate><!--T:36-->
 +
* <tt>components/com_helloworld/language</tt> for the site part (there are no xml languages tag in the site part of the xml description file, but the language folder is included).</translate>
  
{{notice|Please create a pull request or issue at https://github.com/joomla/Joomla-3.2-Hello-World-Component for any code descprepancies or if editing any of the source code on this page.}}
+
{{notice|<translate><!--T:37-->
 +
Please create a pull request or issue at https://github.com/joomla/Joomla-3.2-Hello-World-Component for any code descprepancies or if editing any of the source code on this page.</translate>}}
  
{{:J3.2:Developing a MVC Component/Navigate
+
<translate>== Contributors == <!--T:38--></translate>
|prev=Basic backend <!-- previous article subpage name -->
 
|next=Adding backend actions <!-- next article subpage name -->}}
 
 
 
== Contributors ==
 
 
*[[User:cdemko|Christophe Demko]]
 
*[[User:cdemko|Christophe Demko]]
 
*[[User:oaksu|Ozgur Aksu]]
 
*[[User:oaksu|Ozgur Aksu]]
 +
*[[User:Scionescire|Scionescire]]
 +
 +
<div class="row">
 +
<div class="large-6 columns">{{Basic button|<translate><!--T:39-->
 +
S:MyLanguage/J3.x:Developing_a_MVC_Component/Basic backend|Prev: Basic backend</translate>|class=expand success}}</div>
 +
<div class="large-6 columns">{{Basic button|<translate><!--T:40-->
 +
S:MyLanguage/J3.x:Developing_a_MVC_Component/Adding backend actions|Next: Adding backend actions</translate>|class=expand}}</div>
 +
</div>
  
 +
<noinclude>
 +
<translate>
 +
<!--T:41-->
 +
[[Category:Joomla! 3.x]]
 
[[Category:Joomla! 3.0]]
 
[[Category:Joomla! 3.0]]
 
[[Category:Joomla! 3.1]]
 
[[Category:Joomla! 3.1]]
 
[[Category:Joomla! 3.2]]
 
[[Category:Joomla! 3.2]]
 +
[[Category:Joomla! 3.3]]
 +
[[Category:Joomla! 3.4]]
 
[[Category:Beginner Development]]
 
[[Category:Beginner Development]]
 
[[Category:Component Development]]
 
[[Category:Component Development]]
 +
[[Category:Tutorials]]
 +
[[Category:Tutorials in a Series]]
 +
</translate>
 +
</noinclude>

Revision as of 08:55, 3 July 2015

Other languages:
English • ‎Nederlands • ‎español • ‎français • ‎العربية • ‎中文(台灣)‎
Joomla! 
3.x
Tutorial
Developing a MVC Component



This is a multiple-article series of tutorials on how to develop a Model-View-Controller Component for Joomla! VersionJoomla 3.x.

Begin with the Introduction, and navigate the articles in this series by using the navigation button at the bottom or the box to the right (the Articles in this series).



Copyedit.png
This Page Needs Your Help

This page is tagged because it NEEDS REVIEW. You can help the Joomla! Documentation Wiki by contributing to it.
More pages that need help similar to this one are here. NOTE-If you feel the need is satistified, please remove this notice.


Introduction[edit]

This tutorial is part of the Developing a MVC Component for Joomla! 3.2 tutorial. You are encouraged to read the previous parts of the tutorial before reading this. Joomla! 3.2 manages languages for components in four different situations:

  • displaying a component in the public site
  • managing a component in the backend
  • managing menus in the backend
  • installing a component

Joomla! 3.2 uses two different location folder for languages:

  • one in administrator/language or language
  • one in the component folder (administrator/components/*component*/language or components/*component*/language)

It depends how the component is installed.

Adding language translation in the public site[edit]

With your favorite file manager and editor, put a file site/language/en-GB/en-GB.com_helloworld.ini. This file will contain translation for the public part. For the moment, this file is empty.

site/language/en-GB/en-GB.com_helloworld.ini

For the moment, there are no translations strings in this file.

Adding language translation when managing the component[edit]

With your favorite file manager and editor, put a file admin/language/en-GB/en-GB.com_helloworld.ini. This file will contain translation for the backend part.

admin/language/en-GB/en-GB.com_helloworld.ini

; Joomla! Project
; Copyright (C) 2005 - 2015 Open Source Matters. All rights reserved.
; License GNU General Public License version 2 or later; see LICENSE.txt, see LICENSE.php
; Note : All ini files need to be saved as UTF-8

COM_HELLOWORLD_NUM="#"
COM_HELLOWORLD_PUBLISHED="Published"
COM_HELLOWORLD_HELLOWORLDS_NAME="Name"
COM_HELLOWORLD_ID="Id"

COM_HELLOWORLD_HELLOWORLD_FIELD_GREETING_DESC="This message will be displayed"
COM_HELLOWORLD_HELLOWORLD_FIELD_GREETING_LABEL="Message"
COM_HELLOWORLD_HELLOWORLD_HEADING_GREETING="Greeting"
COM_HELLOWORLD_HELLOWORLD_HEADING_ID="Id"

Adding language translation when managing the menus in the backend[edit]

With your favorite file manager and editor, put a file admin/language/en-GB/en-GB.com_helloworld.sys.ini. This file will contain translation for the backend part.

admin/language/en-GB/en-GB.com_helloworld.sys.ini

; Joomla! Project
; Copyright (C) 2005 - 2015 Open Source Matters. All rights reserved.
; License GNU General Public License version 2 or later; see LICENSE.txt, see LICENSE.php
; Note : All ini files need to be saved as UTF-8

COM_HELLOWORLD="Hello World!"
COM_HELLOWORLD_DESCRIPTION="This is the Hello World description"
COM_HELLOWORLD_HELLOWORLD_VIEW_DEFAULT_TITLE="Hello World"
COM_HELLOWORLD_HELLOWORLD_VIEW_DEFAULT_DESC="This view displays a selected message"
COM_HELLOWORLD_MENU="Hello World!"

Language File Location Options[edit]

Starting with version 1.7 there are 2 ways to install language files for an extension. One can use one or the other or a combination of both.

The 1.5 way will install the files in the CORE language folders (ROOT/administrator/language/ and ROOT/language/). Since version 1.6, include the files in a "language" folder installed at the root of the extension.

Therefore an extension can include a language folder with a .sys.ini different from the one installed in the Joomla core language folders. (This last one not being included in that language folder but in root or any other folder not installed.)

This lets us display 2 different descriptions: one from the sys.ini in the "language" folder is used as a message displayed when installation is finished, the other (from the .ini) is used for "normal" operation, that is, when the extension is edited in the back-end. This can be extremely useful when the installation also uses some scripts and requires a different value for the description.

You Should Note!

The sys.ini file is also used to translate the name of the extensions in some back-end Managers and to provide menu translation for components.

Therefore, the xml would include since 1.6:

<files>
<[...]
<folder>language</folder>  // This folder HAS to include the right subfolders, i.e. language/en-GB/ ... language/fr-FR/
<filename>whatever</filename>
[...]
</files>

<administration>
    <files folder="admin">
        <[...]
        <folder>language</folder>
        <filename>whatever</filename>
        <[...]
    </files>
</administration>

and/or then (1.5 way):

<languages folder="joomlacorelanguagefolders"> // If using another language folder for cleanliness. (Any folder name will fit.)
<language tag="en-GB">en-GB/en-GB.whatever.ini</language> // or
<language tag="en-GB">en-GB.whatever.ini</language> if no tagged subfolder
<language tag="en-GB">en-GB/en-GB.whatever.sys.ini</language> // or
<language tag="en-GB">en-GB.whatever.sys.ini</language> if no tagged subfolder
</languages>

or simply in ROOT:

<languages>
<language tag="en-GB">en-GB.whatever.ini</language>
<language tag="en-GB">en-GB.whatever.sys.ini</language>
</languages>

Language file used by the installation script during the installation of a component(the first install, not an upgrade) obeys specific rules described in the article, Specification of language files. During the first installation, only the language file included in the component folder (/administrator/components/com_helloworld/language) is used when present. If this file is only provided in the CORE language folder (/administrator/language), no translation occurs. This also applies to KEYs used in the manifest file.

When upgrading or uninstalling the extension (not installing), it is the sys.ini file present in the extension root language folder which will display the result of the installation from the description key/value. Thereafter, if present, the sys.ini as well as the .ini installed in the CORE language folder will have priority over the files present in the root language folder of the extension.

Advantages of Extension "Language" Folder

One advantage of installing the files in the extension "language" folder is that these are not touched when updating a language pack.

The other advantage is that this folder can include multiple languages (en-GB always, fr-FR, it-IT, etc.) not requiring the user to install the corresponding language pack. This is handy as they are available if, later on, a user installs the corresponding pack.

Packaging the component[edit]

Content of your code directory

Create a compressed file of this directory or directly download the archive and install it using the extension manager of Joomla. You can add a menu item of this component using the menu manager in the backend.

helloworld.xml

<?xml version="1.0" encoding="utf-8"?>
<extension type="component" version="3.2.0" method="upgrade">

	<name>COM_HELLOWORLD</name>
	<!-- The following elements are optional and free of formatting constraints -->
	<creationDate>January 2014</creationDate>
	<author>John Doe</author>
	<authorEmail>john.doe@example.org</authorEmail>
	<authorUrl>http://www.example.org</authorUrl>
	<copyright>Copyright Info</copyright>
	<license>License Info</license>
	<!--  The version string is recorded in the components table -->
	<version>0.0.8</version>
	<!-- The description is optional and defaults to the name -->
	<description>COM_HELLOWORLD_DESCRIPTION</description>

	<install> <!-- Runs on install -->
		<sql>
			<file driver="mysql" charset="utf8">sql/install.mysql.utf8.sql</file>
		</sql>
	</install>
	<uninstall> <!-- Runs on uninstall -->
		<sql>
			<file driver="mysql" charset="utf8">sql/uninstall.mysql.utf8.sql</file>
		</sql>
	</uninstall>
	<update> <!-- Runs on update; New since J2.5 -->
		<schemas>
			<schemapath type="mysql">sql/updates/mysql</schemapath>
		</schemas>
	</update>

	<!-- Site Main File Copy Section -->
	<!-- Note the folder attribute: This attribute describes the folder
		to copy FROM in the package to install therefore files copied
		in this section are copied from /site/ in the package -->
	<files folder="site">
		<filename>index.html</filename>
		<filename>helloworld.php</filename>
		<filename>controller.php</filename>
		<folder>views</folder>
		<folder>models</folder>
	</files>

        <languages folder="site/language">
		<language tag="en-GB">en-GB/en-GB.com_helloworld.ini</language>
        </languages>

	<administration>
		<!-- Administration Menu Section -->
		<menu link='index.php?option=com_helloworld'>COM_HELLOWORLD_MENU</menu>
		<!-- Administration Main File Copy Section -->
		<!-- Note the folder attribute: This attribute describes the folder
			to copy FROM in the package to install therefore files copied
			in this section are copied from /admin/ in the package -->
		<files folder="admin">
			<!-- Admin Main File Copy Section -->
			<filename>index.html</filename>
			<filename>helloworld.php</filename>
			<filename>controller.php</filename>
			<!-- SQL files section -->
			<folder>sql</folder>
			<!-- tables files section -->
			<folder>tables</folder>
			<!-- models files section -->
			<folder>models</folder>
			<!-- views files section -->
			<folder>views</folder>
		</files>
		<languages folder="admin/language">
        		<language tag="en-GB">en-GB/en-GB.com_helloworld.ini</language>
                        <language tag="en-GB">en-GB/en-GB.com_helloworld.sys.ini</language>
		</languages>
	</administration>

</extension>

In this helloworld.xml file, languages are installed in:

  • administrator/language for the admin part (look at the xml languages tag).
  • components/com_helloworld/language for the site part (there are no xml languages tag in the site part of the xml description file, but the language folder is included).
Info non-talk.png
General Information

Please create a pull request or issue at https://github.com/joomla/Joomla-3.2-Hello-World-Component for any code descprepancies or if editing any of the source code on this page.

Contributors[edit]