Invision Community 4: SEO, prepare for v5 and dormant account notifications By Matt Monday at 02:04 PM
Dima Turchenko Posted January 20, 2017 Posted January 20, 2017 Hi! Can somebody explain how i could manage setting or just custom values like title of links or buttons per lang if i have more then one language? with example or send me some good link for reading Thanks!
Meddysong Posted January 20, 2017 Posted January 20, 2017 Give this a read: https://invisionpower.com/4guides/themes-and-customizations/languages-and-localization_326/
Dima Turchenko Posted January 23, 2017 Author Posted January 23, 2017 Ok. Pls imagine, I have created my custom button and wanna display it title by lang1 or lang2, so i need to create lang pack or what? I guess this is very complicated manipulation for such a simple task, dont u think? usually there is en/blog_lang.php, de/blog_lang.php or en_EN.php, de_DE.php And system automatically loads suitable lang file by existing langs
bfarber Posted January 23, 2017 Posted January 23, 2017 If the string you want to display is a static string you defined, then you simply put the string in a language file. i.e. for a plugin it would be plugins/(yourplugin)/dev/lang.php in the format of <?php $lang = array( 'key1' => "This is the text to display", 'key2' => "Button String" ); Be sure to use unique keys (maybe pluginkey_somethingelse) as they are not namespaced in any way. From there, you simply use this in your teplates {lang="key1"} Or this in your controllers \IPS\Member::loggedIn()->language()->addToStack( 'key1' ); The system supports more complex things like inserting URLs and using sprintf (both with and without automatic escaping of HTML characters) as needed. You only define the English language strings. Authors of language packs, and site operators, will define the keys in other languages beyond English. There is no way for you to ship the German, etc. translations with your application or plugin I'm afraid. If you want to create a form field to allow admins to translate directly, you use the Translatable form helper. Here's an example for the forum name field. $form->add( new \IPS\Helpers\Form\Translatable( 'forum_name', NULL, TRUE, array( 'app' => 'forums', 'key' => ( $this->id ? "forums_forum_{$this->id}" : NULL ) ) ) ); As a general rule we do not present translatable fields on the front end, only in the ACP.
Recommended Posts
Archived
This topic is now archived and is closed to further replies.