Difference between revisions of "How to edit the JReviews language files"
(15 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
+ | <div class="successbox" style="width: 95%"> | ||
+ | |||
+ | [https://www.jreviews.com/docs/languages-and-localization There's a new version of this article] | ||
+ | |||
+ | </div> | ||
+ | |||
+ | __TOC__ | ||
+ | |||
+ | |||
+ | = Translating JReviews core language files = | ||
+ | |||
JReviews uses language files for all the text that is used in the themes. To change the text or translate it to a different language you need to edit the files in: | JReviews uses language files for all the text that is used in the themes. To change the text or translate it to a different language you need to edit the files in: | ||
+ | |||
+ | Joomla: | ||
+ | |||
*<span style="color: blue">/components/com_jreviews/jreviews/locale/</span> | *<span style="color: blue">/components/com_jreviews/jreviews/locale/</span> | ||
+ | WordPress: | ||
− | + | *<span style="color: blue">/wp-content/plugins/jreviews/jreviews/locale/</span> | |
− | When translating or changing the .po file it is very important to keep the character encoding of the file. In order to do this you need to use a special editor like Notepad++ or Poedit. Both are free applications. | + | There's a folder for each language. To modify the language files use the JReviews overrides folder so you don't lose your changes when you upgrade. If you haven't already created the overrides folder, you should create it under the Joomla templates folder: |
+ | |||
+ | Joomla: | ||
+ | |||
+ | *<span style="color: blue">SITE_ROOT/templates/jreviews_overrides/</span> | ||
+ | |||
+ | WordPress: | ||
+ | |||
+ | *<span style="color: blue">SITE_ROOT/jreviews_overrides/</span> | ||
+ | |||
+ | Then if you want to make changes to the Spanish language default.po file, you '''create an empty default.po''' file in: | ||
+ | |||
+ | Joomla: | ||
+ | |||
+ | *<span style="color: blue">/templates/jreviews_overrides/locale/spa/LC_MESSAGES/default.po</span> | ||
+ | |||
+ | WordPress: | ||
+ | |||
+ | *<span style="color: blue">/jreviews_overrides/locale/spa/LC_MESSAGES/default.po</span> | ||
+ | |||
+ | And proceed to '''add only the language strings you want to modify'''. | ||
+ | |||
+ | <span style="display:block; padding: 10px; background: #fbcad6; color: #c90e3e;">When translating or changing the .po file, it is very important to keep the character encoding of the file. In order to do this you need to use a special editor like Notepad++ or Poedit. Both are free applications. '''The files must be saved with UTF-8 encoding.'''</span> | ||
When changing the file it is only necessary to change the msgstr, changing the msgid will not work. For example: | When changing the file it is only necessary to change the msgstr, changing the msgid will not work. For example: | ||
<source lang="php"> | <source lang="php"> | ||
− | |||
− | |||
msgid "Submit" | msgid "Submit" | ||
msgstr "Submit" | msgstr "Submit" | ||
</source> | </source> | ||
− | |||
Would be changed like this for a Spanish translation: | Would be changed like this for a Spanish translation: | ||
<source lang="php"> | <source lang="php"> | ||
− | |||
− | |||
msgid "Submit" | msgid "Submit" | ||
msgstr "Enviar" | msgstr "Enviar" | ||
</source> | </source> | ||
− | |||
The msgid serves as the lookup reference from the .thtml theme files, where you'll find it in this format: | The msgid serves as the lookup reference from the .thtml theme files, where you'll find it in this format: | ||
Line 32: | Line 63: | ||
__t("Submit"); | __t("Submit"); | ||
</source> | </source> | ||
− | |||
There is no need to change the theme .thtml files for translation, but if you do change the references in the __t("text"); format, then those will not be translatable via the language file unless you add to them new reference: | There is no need to change the theme .thtml files for translation, but if you do change the references in the __t("text"); format, then those will not be translatable via the language file unless you add to them new reference: | ||
msgid "text" | msgid "text" | ||
+ | |||
msgstr "translated text" | msgstr "translated text" | ||
− | '''After making changes to a language file you must clear the cache in JReviews''' using the "Clear | + | '''After making changes to a language file you must clear the cache in JReviews''' using the "Clear Cache & File Registry" link in the JReviews administration. |
+ | |||
+ | [[File:cache-fileregistry.png]] | ||
+ | |||
+ | You need to do this even if caching is disabled in JReviews. | ||
+ | |||
+ | It is recommended to use the [[JReviews Code Overrides]] functionality to make modifications to language files outside the /com_jreviews folder so that your changes are not lost after you upgrade JReviews. | ||
+ | |||
+ | For example, if you want to customize the spanish language, copy the spanish language folder: | ||
+ | |||
+ | Joomla: | ||
+ | |||
+ | *<span style="color: blue">/components/com_jreviews/jreviews/locale/spa/</span> | ||
+ | |||
+ | WordPress: | ||
+ | |||
+ | *<span style="color: blue">/wp-content/plugins/jreviews/jreviews/locale/spa/</span> | ||
+ | |||
+ | into the jreviews_overrides folder like this: | ||
+ | |||
+ | Joomla: | ||
+ | |||
+ | *<span style="color: blue">/templates/jreviews_overrides/locale/spa/</span> | ||
+ | |||
+ | WordPress: | ||
+ | |||
+ | *<span style="color: blue">/jreviews_overrides/locale/spa/</span> | ||
+ | |||
+ | The language file in overrides doesn't need to contain all translations, you can delete everything from the file except the translations that you want to modify. | ||
+ | |||
+ | Every JReviews add-on also has a language file. If you want to customize those translations as well, you can do it inside the same language file where you have JReviews translations. | ||
+ | |||
+ | = Translating JReviews Add-on language files = | ||
+ | |||
+ | For add-ons you can find the language folders in: | ||
+ | |||
+ | Joomla: | ||
+ | |||
+ | *<span style="color: blue">/components/com_jreviews_addons/addon-name/locale/</span> | ||
+ | |||
+ | WordPress: | ||
+ | |||
+ | *<span style="color: blue">/wp-content/plugins/jreviews_addons/addon-name/locale/</span> | ||
+ | |||
+ | You will use the same language file override for both JReviews core and Add-ons. So if you want to override an Add-ons language strings, first you create the language override file as explained above, and then add only the Add-on strings you want to override to this file. | ||
+ | |||
+ | = Troubleshooting = | ||
+ | |||
+ | If your language overrides are not working there are two things you can check: | ||
+ | # Clear the file registry in the JReviews administration to ensure that your new language override file and strings are read and processed. | ||
+ | # Make sure you are using the correct '''msgid''' in your language string overrides. To do this, open the original language file, either in your language or the English file if the translation is missing in your language, and lookup the string you see in the JReviews front-end. Sometimes constants are used for the msgid instead of natural language, so this step is important. | ||
Latest revision as of 20:47, 24 April 2020
Contents
Translating JReviews core language files
JReviews uses language files for all the text that is used in the themes. To change the text or translate it to a different language you need to edit the files in:
Joomla:
- /components/com_jreviews/jreviews/locale/
WordPress:
- /wp-content/plugins/jreviews/jreviews/locale/
There's a folder for each language. To modify the language files use the JReviews overrides folder so you don't lose your changes when you upgrade. If you haven't already created the overrides folder, you should create it under the Joomla templates folder:
Joomla:
- SITE_ROOT/templates/jreviews_overrides/
WordPress:
- SITE_ROOT/jreviews_overrides/
Then if you want to make changes to the Spanish language default.po file, you create an empty default.po file in:
Joomla:
- /templates/jreviews_overrides/locale/spa/LC_MESSAGES/default.po
WordPress:
- /jreviews_overrides/locale/spa/LC_MESSAGES/default.po
And proceed to add only the language strings you want to modify.
When translating or changing the .po file, it is very important to keep the character encoding of the file. In order to do this you need to use a special editor like Notepad++ or Poedit. Both are free applications. The files must be saved with UTF-8 encoding.
When changing the file it is only necessary to change the msgstr, changing the msgid will not work. For example:
msgid "Submit" msgstr "Submit"
Would be changed like this for a Spanish translation:
msgid "Submit" msgstr "Enviar"
The msgid serves as the lookup reference from the .thtml theme files, where you'll find it in this format:
__t("Submit");
There is no need to change the theme .thtml files for translation, but if you do change the references in the __t("text"); format, then those will not be translatable via the language file unless you add to them new reference:
msgid "text"
msgstr "translated text"
After making changes to a language file you must clear the cache in JReviews using the "Clear Cache & File Registry" link in the JReviews administration.
You need to do this even if caching is disabled in JReviews.
It is recommended to use the JReviews Code Overrides functionality to make modifications to language files outside the /com_jreviews folder so that your changes are not lost after you upgrade JReviews.
For example, if you want to customize the spanish language, copy the spanish language folder:
Joomla:
- /components/com_jreviews/jreviews/locale/spa/
WordPress:
- /wp-content/plugins/jreviews/jreviews/locale/spa/
into the jreviews_overrides folder like this:
Joomla:
- /templates/jreviews_overrides/locale/spa/
WordPress:
- /jreviews_overrides/locale/spa/
The language file in overrides doesn't need to contain all translations, you can delete everything from the file except the translations that you want to modify.
Every JReviews add-on also has a language file. If you want to customize those translations as well, you can do it inside the same language file where you have JReviews translations.
Translating JReviews Add-on language files
For add-ons you can find the language folders in:
Joomla:
- /components/com_jreviews_addons/addon-name/locale/
WordPress:
- /wp-content/plugins/jreviews_addons/addon-name/locale/
You will use the same language file override for both JReviews core and Add-ons. So if you want to override an Add-ons language strings, first you create the language override file as explained above, and then add only the Add-on strings you want to override to this file.
Troubleshooting
If your language overrides are not working there are two things you can check:
- Clear the file registry in the JReviews administration to ensure that your new language override file and strings are read and processed.
- Make sure you are using the correct msgid in your language string overrides. To do this, open the original language file, either in your language or the English file if the translation is missing in your language, and lookup the string you see in the JReviews front-end. Sometimes constants are used for the msgid instead of natural language, so this step is important.