Travo Posted June 15, 2016 Share Posted June 15, 2016 How would I go about translating a long list of variables? For example, I have defined a list of all possible languages as a PHP dictionary, but writing each one down by hand would be too much work (I have about 500 entries in total, including languages and countries), Is there way to import the translation values from JSON? public static function LANGUAGES() { return [ "tk" => _x("Turkmen", "language"), "ku" => _x("Kurdish", "language"), "ht" => _x("Haitian", "language"), [.....snip.....] ]; } Link to comment Share on other sites More sharing options...
tpr Posted June 15, 2016 Share Posted June 15, 2016 I would recommend creating a page for it and add field or fields to translate: https://processwire.com/talk/topic/10443-how-to-do-this-global-vars/ Alternativel you can apply the technique discussed here: https://processwire.com/talk/topic/10447-using-translatable-strings-across-template-files/ Link to comment Share on other sites More sharing options...
Travo Posted June 15, 2016 Author Share Posted June 15, 2016 Thanks. I went for what I initially had as well: a TextareaLanguage field on a page, containing a formatted list (one per list, key and value separated with a colon). I also implemented a translation strings file. Link to comment Share on other sites More sharing options...
tpr Posted June 15, 2016 Share Posted June 15, 2016 Maybe you can use Multivalue Textformatter. Link to comment Share on other sites More sharing options...
Travo Posted June 15, 2016 Author Share Posted June 15, 2016 I solved it like this: class Lookup { public static function COUNTRIES($pages) { return self::dictionaryFromField(self::getLookupPage($pages)->Lookup_Countries); } protected static function getLookupPage($pages) { return $pages->findOne('template=lookup-page, include=all'); } protected static function dictionaryFromField($fieldValue) { $returnDictionary = []; foreach (preg_split('/\R/', $fieldValue) as $line) { $explodedLine = explode(':', $line); $returnDictionary[trim($explodedLine[0])] = trim($explodedLine[1]); } return $returnDictionary; } } Obviously, I have a lot of other lookup lists besides countries there. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now