Patrik Posted May 23, 2013 Share Posted May 23, 2013 Hi all, I'm developing a PW site with two languages, and have come to the point where I need to translate some static strings. I'm now trying to figure out how this works, but not sure if I really get it. In the admin language section, I added one of my template files that contains a few strings with the __() function, and was able to translate it easily. But do I really need to add every single one of my templates? Is there no way to add the whole templates folder or keep all translations in a single file? Please give me some pointers here. Thanks! Link to comment Share on other sites More sharing options...
Soma Posted May 23, 2013 Share Posted May 23, 2013 Don't use PW translation for static text on front-end. I highly encourage to use some php vars or yaml to translate. So you can have de.yaml with suche: "Suche" suchen: "suchen" suchresultat: "Suchresultat" suchbegriff_eingeben: "Bitte geben Sie einen Suchbegriff ein." treffer_gefunden: "{s} hat {c} Treffer ergeben:" keine_treffer: "Keine Resultate gefunden" ... And a script in the header that loads and parses the file depending on the language. Example from one of my sites using symphony yaml class: require_once($config->paths->root . "site/libs/yaml/sfYaml.php"); require_once($config->paths->root . "site/libs/yaml/sfYamlParser.php"); // instance a parser object $yaml = new sfYamlParser(); // parse language file $txt = $yaml->parse(file_get_contents($config->paths->root . "site/languages/" . $lang . ".yaml")); Now you can have localized text echo $txt['suche']; Link to comment Share on other sites More sharing options...
interrobang Posted May 23, 2013 Share Posted May 23, 2013 You can also create a single file with all your translateable strings and use this file as your Textdomain in your __() calls. For more infos look in the API docs: http://processwire.com/api/multi-language-support/code-i18n/ (scroll down to TECHNICAL DETAILS/Using Textdomains) Link to comment Share on other sites More sharing options...
ryan Posted May 25, 2013 Share Posted May 25, 2013 Placing your translatable text in __() function calls is the recommended way to go. It's also the way that PHP gettext() works (though it uses _() rather than __()) and is a universal standard. If you want to keep all your translations in a single file, then that's certainly fine. But I think that's ultimately creating more work for yourself as you end up having to refer to translated text via keys rather than the actual text. The only situation where I might use keys are if I need to re-use the same phrase multiple times, across multiple templates… which would save having to translate the same text more than once. 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