This shows you the differences between two versions of the page.
Next revision | Previous revision Next revision Both sides next revision | ||
ru:plugins:i18n [2013/10/09 11:10] Arkady created |
ru:plugins:i18n [2013/10/09 11:17] Arkady [Language files without country] |
||
---|---|---|---|
Line 15: | Line 15: | ||
</code> | </code> | ||
- | If your plugin also supports GetSimple 2.03, you would rather have to use: | + | Если ваш плагин поддерживает и GetSimple 2.03, используйте следующий код: |
<code> | <code> | ||
Line 22: | Line 22: | ||
</code> | </code> | ||
- | A (not necessarily up-to-date) list of the built in i18n hashes can be found [[i18nhashes|on this page]]. Always check the source for the latest. | ||
- | If you need additional texts not found in the standard GetSimple translation files, you need to create translation files yourself. They should look like the GetSimple translation files, e.g. de_DE.php: | + | Список встроенных в систему ключей для перевода со значениями можно найти [[i18nhashes|на этой странице]], хотя он не всегда соответствует текущей версии. Самая актуальная версия содержится, конечно, в исходниках GetSimple. |
+ | |||
+ | Если вы хотите добавить в файл перевода собственные ключи, отсутствующие в файлах GetSimple, добавьте их в свой языковой файл с переводом самостоятельно, например, для русского языка (ru_RU.php) это будет выглядеть так: | ||
<code> | <code> | ||
$i18n = array( | $i18n = array( | ||
- | 'BTN_SAVEMYSETTINGS' => 'Meine Einstellungen speichern', | + | 'BTN_SAVEMYSETTINGS' => 'Моя кнопка для сохранения изменений', |
- | 'MYHEADER' => 'Meine Uberschrift' | + | 'MYHEADER' => 'Мой заголовок' |
); | ); | ||
</code> | </code> | ||
- | Put all your plugin specific language files into the directory ''my_plugin/lang/'', thus giving you a plugin with the following files: | + | Все языковые файлы размещаются в директории //мой_плагин/lang///, структура файлов плагина должна выглядеть следующим образом: |
<code> | <code> | ||
- | - my_plugin.php | + | - мой_плагин.php |
- | - my_plugin (directory) | + | - мой_плагин (директория) |
- | - .htaccess (with one line: Deny from all) | + | - .htaccess (с одной строкой: Deny from all) |
- lang (directory) | - lang (directory) | ||
- | - .htaccess (with one line: Deny from all) | + | - .htaccess (с одной строкой: Deny from all) |
- en_US.php | - en_US.php | ||
- | - de_DE.php | + | - de_DE.php (если есть такой файл) |
- | - it_IT.php | + | - ru_RU.php |
</code> | </code> | ||
- | GetSimple 3.0 makes it easy to load these texts in your plugin, e.g.: | + | Начиная с версии GetSimple 3.0 строки перевода из языкового файла легко подгружаются с помощью следующего кода: |
<code> | <code> | ||
- | i18n_merge('my_plugin') || i18n_merge('my_plugin','en_US'); | + | i18n_merge('мой_плагин') || i18n_merge('мой_плагин ','en_US'); |
</code> | </code> | ||
- | This will try to get the translations for the current admin language, and - if this fails - load the english texts. You need to make sure that the default language (here ''en_US'') texts do exist, e.g. ''my_plugin/lang/en_US.php''. | + | Система пытается получить перевод для текущего языка системы, установленного в административной панели в GetSimple. Если попытка не удается, то загружаются строки из английского языкового файла вашего плагина. Разумеется, такой файл для английского языка по умолчанию под именем en_US.php должен находиться в папке ''Мой_плагин/lang/en_US.php'' вашего плагина. |
- | You then access them in the same way as standard GetSimple texts, but add your plugin name as prefix to the key, e.g. | + | Доступ к языковому файлу вашего плагина очень похож на стандартный код GetSimple для такого случая, вы только должны добавить наименование плагина как префикс к ключу: |
<code> | <code> | ||
- | <input type="submit" name="save" value="<?php i18n("my_plugin/BTN_SAVEMYSETTINGS"); ?>"/> | + | <input type="submit" name="save" value="<?php i18n("мой_плагин/BTN_SAVEMYSETTINGS"); ?>"/> |
</code> | </code> | ||
- | Note that //i18n()// echos the translation. If you need to use the translated text in php code you will have to use //i18n_r()// to return the string rather than echoing it, e.g. | + | Обратите внимание, что функция //i18n()// выводит результат перевода на экран. Если вам необходимо использовать переведенный текст в PHP-коде, используйте функцию //i18n_r()//, которая возвращает переведенную строку, например: |
<code> | <code> | ||
- | $msg = '<div style="display: block;" class="updated">' . i18n_r("my_plugin/MSG_UPDATED") . '.</div>'; | + | $msg = '<div style="display: block;" class="updated">' . i18n_r("мой_плагин/MSG_UPDATED") . '.</div>'; |
echo $msg; | echo $msg; | ||
</code> | </code> | ||
- | That's it. Just provide at least one language file (preferably english - ''en_US'') and wait for the community to provide translations into other languages, then include them in your plugin. | + | Вот как-то так. С плагином достаточно поставлять хотя бы один языковой файл (разумеется, лучше английский) и спокойно ждать, пока кто-то из сообщества не сделает перевод на другой язык. После этого можете включать новый языковой файл в состав своего плагина. |
- | ===== Language files without country ===== | + | ===== Языковые файлы без кода страны ===== |
- | If you want to provide language files en.php, de.php, etc. (without country code), than use the following lines to load your texts: | + | Если вы в плагине применяете языковые файлы без кода страны, т.е. en.php, de.php, и.т.д., используйте для подгрузки перевода следующий код: |
<code> | <code> | ||
global $LANG; | global $LANG; | ||
- | i18n_merge('my_plugin', substr($LANG,0,2)) || i18n_merge('my_plugin','en'); | + | i18n_merge('мой_плагин', substr($LANG,0,2)) || i18n_merge('мой_плагин','en'); |
</code> | </code> | ||
+ | |||
+ | |||
===== Front-end ===== | ===== Front-end ===== |