sodesign Posted February 23, 2023 Share Posted February 23, 2023 I'm writing a custom translation exported for a client and I'm having trouble outputting static translations in languages other than the default. Here's what I'm trying to do, but it's just outputting English both times. I must be missing something, but can't see anything in the docs or forum about how to acheive this. <?php function echoSnippet($string, $lang) { // Echo the string in english wire('user')->setLanguage(wire('languages')->get('name=en')); echo __($string); // Echo the string in german wire('user')->setLanguage($lang); echo __($string); } $lang = $languages->get("name=de"); echoSnippet("Page not found", $lang); Does anyone have any pointers? Thanks! Link to comment Share on other sites More sharing options...
da² Posted July 3, 2023 Share Posted July 3, 2023 Hello, I suppose this is due to text domain. You are asking for a translation that has been defined in another file, so to get it you need to specify the text domain of this file. echo __($string, '/site/templates/file_containing_translation.php'); If you want to automatically export translations, I think you should put all translations in a single file, let say it's named _commonTranslations.php: __('translation 1'); __('translation 2'); // And so on... Then when you insert this translations in the template that needs it, you need to specify text domain (you can put it in a constant or create a global function that inserts it automatically): __('translation 1', '/site/templates/_commonTranslations.php'); Note that in PW, you translate this sentences ONLY in _commonTranslations.php. Finally your function looks like that: function echoSnippet($string, $lang) { // Echo the string in english wire('user')->setLanguage(wire('languages')->get('name=en')); echo __($string, '/site/templates/_commonTranslations.php'); // Echo the string in german wire('user')->setLanguage($lang); echo __($string, '/site/templates/_commonTranslations.php'); } 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