J3.x

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

From Joomla! Documentation

< J3.x:Developing an MVC Component
(Add link to step 8 archive)
(Some markup changes and corrections for Words2Watch compliance.)
 
(22 intermediate revisions by 10 users not shown)
Line 1: Line 1:
{{:J3.1:Developing a MVC Component}}
+
<noinclude><languages /></noinclude>
 
 
 
{{review}}
 
{{review}}
 +
{{:J3.1:Developing an MVC Component/<translate><!--T:1-->
 +
en</translate>}}
 +
<translate>== Introduction == <!--T:2--></translate>
 +
<translate><!--T:3-->
 +
This tutorial is part of the [[S:MyLanguage/J3.2:Developing an MVC Component | Developing an MVC Component for Joomla! 3.2]] tutorial. You are encouraged to read the previous parts of the tutorial before reading this.</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:42--> You can watch a video associated with this step in the tutorial at</translate> [https://www.youtube.com/watch?v=jRVjozY_XGM <translate><!--T:43--> Step 8, Adding Language Management</translate>].
  
== Introduction ==
+
{{#widget:YouTube|id=jRVjozY_XGM}}
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><!--T:4-->
 +
Joomla! 3.2 manages languages for components in four different situations:</translate>
 +
<translate><!--T:5-->
 
* 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 folders 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 favourite 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 ==
+
programming
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>== Adding Language Translation when Managing the Component == <!--T:13--></translate>
 +
<translate><!--T:14-->
 +
With your favourite 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 - 2018 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 favourite 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 84:
 
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>
  
The 1.5 way will install the files in the CORE language folders (ROOT/administrator/language/ and ROOT/language/ ).
+
<translate><!--T:19-->
Since 1.6— includes the files in a "language" folder installed at the root of the extension.
+
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>
  
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).
+
<translate><!--T:20-->
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.
+
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>
This can be extremely useful when installing also uses some scripts and requires a different value for the description.
 
  
{{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:21-->
 +
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>
 +
 
 +
{{tip|<translate><!--T:22-->
 +
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-->
 +
You Should Note!</translate>}}
 +
 
 +
<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>
 
<[...]
 
<[...]
<folder>language</folder>  // This folder HAS to include the right subfolders, i.e. language/en-GB/ ... language/fr-FR/
+
<folder>language</folder>  // This folder HAS to include the right subfolders, i.e. ''language/en-GB/'' ... ''language/fr-FR/''
 
<filename>whatever</filename>
 
<filename>whatever</filename>
 
[...]
 
[...]
 
</files>
 
</files>
 +
 +
<administration>
 +
    <files folder="admin">
 +
        <[...]
 +
        <folder>language</folder>
 +
        <filename>whatever</filename>
 +
        <[...]
 +
    </files>
 +
</administration>
 
</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 91: Line 139:
 
</source>
 
</source>
  
or simply in ROOT
+
<translate><!--T:26-->
 +
or simply in ROOT:</translate>
 +
 
 
<source lang="xml">
 
<source lang="xml">
 
<languages>
 
<languages>
Line 99: Line 149:
 
</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.
 
 
 
{{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.}}
 
 
 
== Adding translation when installing the component ==
 
 
 
See: [[#Language_File_Location_Options|Language File Location Options]]
 
  
With your favorite file manager and editor, put a file ''EXTENSIONROOT/language/en-GB/en-GB.myextension.sys.ini''. This file will contain translation for the install.
+
<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>
  
<span id="language/en-GB/en-GB.com_helloworld.sys.ini">
+
{{tip|title=<translate><!--T:29-->
''language/en-GB/en-GB.com_helloworld.sys.ini''
+
Advantages of Extension ''Language'' Folder</translate>|<translate><!--T:30-->
<source lang="ini">
+
''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>}}
COM_HELLOWORLD="Hello World!"
 
COM_HELLOWORLD_DESCRIPTION="This is the Hello World description"
 
</source>
 
</span>
 
  
The ''COM_HELLOWORLD_DESCRIPTION'' can be used in the [[#helloworld.xml|helloworld.xml]] file
+
<translate>== Packaging the Component == <!--T:31--></translate>
  
== Packaging the component ==
+
<translate><!--T:32-->
 
+
Content of your code directory</translate>
Content of your code directory
 
 
* ''[[#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_an_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_an_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_an_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_an_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_an_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_an_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_an_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_an_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_an_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_an_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_an_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_an_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_an_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_an_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_an_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_an_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_an_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_an_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_an_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_an_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_an_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_an_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_an_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_an_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_an_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_an_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_an_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_an_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_an_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_an_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_an_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_an_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_an_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_an_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_an_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_an_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.0" method="upgrade">
+
<extension type="component" version="3.0" method="upgrade">
 +
 
 +
<name>COM_HELLOWORLD</name>
 +
<!-- The following elements are optional and free of formatting constraints -->
 +
<creationDate>January 2018</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>
  
    <name>COM_HELLOWORLD</name>
+
<install> <!-- Runs on install -->
    <!-- The following elements are optional and free of formatting constraints -->
+
<sql>
    <creationDate>January 2014</creationDate>
+
<file driver="mysql" charset="utf8">sql/install.mysql.utf8.sql</file>
    <author>John Doe</author>
+
</sql>
    <authorEmail>john.doe@example.org</authorEmail>
+
</install>
    <authorUrl>http://www.example.org</authorUrl>
+
<uninstall> <!-- Runs on uninstall -->
    <copyright>Copyright Info</copyright>
+
<sql>
    <license>License Info</license>
+
<file driver="mysql" charset="utf8">sql/uninstall.mysql.utf8.sql</file>
    <!-- The version string is recorded in the components table -->
+
</sql>
    <version>0.0.8</version>
+
</uninstall>
    <!-- The description is optional and defaults to the name -->
+
<update> <!-- Runs on update; New since J2.5 -->
    <description>COM_HELLOWORLD_DESCRIPTION</description>
+
<schemas>
 +
<schemapath type="mysql">sql/updates/mysql</schemapath>
 +
</schemas>
 +
</update>
  
    <install> <!-- Runs on install -->
+
<!-- Site Main File Copy Section -->
        <sql>
+
<!-- Note the folder attribute: This attribute describes the folder
            <file driver="mysql" charset="utf8">sql/install.mysql.utf8.sql</file>
+
to copy FROM in the package to install therefore files copied
        </sql>
+
in this section are copied from /site/ in the package -->
    </install>
+
<files folder="site">
    <uninstall> <!-- Runs on uninstall -->
+
<filename>index.html</filename>
        <sql>
+
<filename>helloworld.php</filename>
            <file driver="mysql" charset="utf8">sql/uninstall.mysql.utf8.sql</file>
+
<filename>controller.php</filename>
        </sql>
+
<folder>views</folder>
    </uninstall>
+
<folder>models</folder>
    <update> <!-- Runs on update; New in 2.5 -->
+
</files>
        <schemas>
 
            <schemapath type="mysql">sql/updates/mysql</schemapath>
 
        </schemas>
 
    </update>
 
  
    <!-- Site Main File Copy Section -->
+
<languages folder="site/language">
    <!-- Note the folder attribute: This attribute describes the folder
+
<language tag="en-GB">en-GB/en-GB.com_helloworld.ini</language>
            to copy FROM in the package to install therefore files copied
+
</languages>
            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>
 
        <folder>language</folder>
 
    </files>
 
  
    <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
                to copy FROM in the package to install therefore files copied
+
to copy FROM in the package to install therefore files copied
                in this section are copied from /admin/ in the package -->
+
in this section are copied from /admin/ in the package -->
        <files folder="admin">
+
<files folder="admin">
            <!-- Admin Main File Copy Section -->
+
<!-- Admin Main File Copy Section -->
            <filename>index.html</filename>
+
<filename>index.html</filename>
            <filename>helloworld.php</filename>
+
<filename>helloworld.php</filename>
            <filename>controller.php</filename>
+
<filename>controller.php</filename>
            <!-- SQL files section -->
+
<!-- SQL files section -->
            <folder>sql</folder>
+
<folder>sql</folder>
            <!-- tables files section -->
+
<!-- tables files section -->
            <folder>tables</folder>
+
<folder>tables</folder>
            <!-- models files section -->
+
<!-- models files section -->
            <folder>models</folder>
+
<folder>models</folder>
            <!-- views files section -->
+
<!-- views files section -->
            <folder>views</folder>
+
<folder>views</folder>
            <!-- admin languages files section -->
+
</files>
            <folder>language</folder>
+
<languages folder="admin/language">
        </files>
+
<language tag="en-GB">en-GB/en-GB.com_helloworld.ini</language>
    </administration>
+
<language tag="en-GB">en-GB/en-GB.com_helloworld.sys.ini</language>
 +
</languages>
 +
</administration>
  
 
</extension>
 
</extension>
Line 246: Line 289:
 
</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 Joomla-3.2-Hello-World-Component] for any code discrepancies 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_an_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_an_MVC_Component/Adding backend actions|Next: Adding backend actions</translate>|class=expand}}</div>
 +
</div>
 +
__NOTOC__
  
[[Category:Joomla! 3.0]]
+
[[Category:Joomla! 3.x{{#translation:}}]]
[[Category:Joomla! 3.1]]
+
[[Category:Joomla! 3.0{{#translation:}}]]
[[Category:Joomla! 3.2]]
+
[[Category:Joomla! 3.1{{#translation:}}]]
[[Category:Beginner Development]]
+
[[Category:Joomla! 3.2{{#translation:}}]]
[[Category:Component Development]]
+
[[Category:Joomla! 3.3{{#translation:}}]]
 +
[[Category:Joomla! 3.4{{#translation:}}]]
 +
[[Category:Beginner Development{{#translation:}}]]
 +
[[Category:Component Development{{#translation:}}]]
 +
[[Category:Tutorials{{#translation:}}]]
 +
[[Category:Tutorials in a Series{{#translation:}}]]
 +
</noinclude>

Latest revision as of 18:11, 23 July 2022

Other languages:
English • ‎Nederlands • ‎español • ‎français • ‎العربية • ‎中文(台灣)‎
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.


Joomla! 
3.x
Tutorial
Developing an 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).



Introduction[edit]

This tutorial is part of the Developing an MVC Component for Joomla! 3.2 tutorial. You are encouraged to read the previous parts of the tutorial before reading this.

You can watch a video associated with this step in the tutorial at Step 8, Adding Language Management.

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 folders 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 favourite 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. programming

Adding Language Translation when Managing the Component[edit]

With your favourite 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 - 2018 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 favourite 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.0" method="upgrade">

	<name>COM_HELLOWORLD</name>
	<!-- The following elements are optional and free of formatting constraints -->
	<creationDate>January 2018</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 Joomla-3.2-Hello-World-Component for any code discrepancies or if editing any of the source code on this page.

Contributors[edit]