Jump to content

Translating long lists (batch translate)


Travo
 Share

Recommended Posts

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

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...