LAPS Posted November 16, 2018 Share Posted November 16, 2018 Hi, I've successfully installed and used Language Support & Co. and Functional Fields modules so that I can translate almost all the strings of my website in English (default) and Italian. Now, in my template files I've "See also" strings that I would like to translate globally (not per template by using Functional Fields). How should I make this? I read the doc and maybe what I need is to use the textdomain, but I didn't understand how to use it. That is, what text/code should be in the file? any example? Also, in the admin area I have the menu items Default and Italian under Setup > Languages. Once accessed one of them, there is the field "Site Translation Files" with the description: "Use this field for translations specific to your site (like files in /site/templates/ for example)". Should I use this field (instead of textdomains) to set globally translated strings? If so, what text/code should be in the file? any example? Link to comment Share on other sites More sharing options...
kixe Posted November 16, 2018 Share Posted November 16, 2018 I do it usually as follows: 1.) Create a file /site/translations.php <?php namespace ProcessWire; /** * TRANSLATABLE STRINGS * Define globally available translatable strings * * USAGE * place this file under /site/translations.php * __("My translatable string", $ferry); * The wire property $ferry refers to the textdomain of this file * */ __("My translatable string"); 2.) Define a wire derived object and place it in /site/ready.php /** * TRANSLATABLE STRINGS * Include translatable strings * @see /site/translations.php * @var $ferry */ $this->wire('ferry', '/site/translations.php', true); output in any template /** * output in template */ echo __("My translatable string", $ferry); Now you need to translate it only once, by using the string in any template. Usecase: strings like "read more" etc. For strings specific to a template you can use simply: /** * output in template */ echo __("My translatable string"); 7 2 Link to comment Share on other sites More sharing options...
LAPS Posted November 16, 2018 Author Share Posted November 16, 2018 How do you translate the string? That is, where do you put English and (in my case) Italian strings (I see only the English one in file /site/translations.php)? What do you think about this solution? Link to comment Share on other sites More sharing options...
kixe Posted November 17, 2018 Share Posted November 17, 2018 21 hours ago, LAPS said: What do you think about this solution? Of course a good solution using the database instead of textdomain 21 hours ago, LAPS said: How do you translate the string? To translate globally defined strings as described in my post: go to SETUP > LANGUAGES > ITALIAN klick button "Find files to translate" select /site/translations.php start to translate 1 Link to comment Share on other sites More sharing options...
szabesz Posted February 27, 2019 Share Posted February 27, 2019 Hi @kixe Thanks for this technique! I followed your instructions and it seems to work as expected, however I get the following message on the translate page, maybe you or someone else can explain why and/or what it means: Quote Translate to other languages: Unable to load textdomain for other languages. see the screenshot: Any ideas? Thanks in advance. Link to comment Share on other sites More sharing options...
tpr Posted February 27, 2019 Share Posted February 27, 2019 It should be AOS, if the same file is added for translation in other languages you can navigate easily between the them. 2 Link to comment Share on other sites More sharing options...
szabesz Posted February 27, 2019 Share Posted February 27, 2019 1 hour ago, tpr said: It should be AOS, if the same file is added for translation in other languages you can navigate easily between the them. I see, thanks for the quick reply! Yes, disabling AdminOnSteroids "makes it go away". I thought it might be some sort of issue I must be aware of. I can live with it, I mean because the site will not have another language just the default plus English there will be no other translations to switch to. BTW, would it be possible to somehow show us what is modified/added by AOS? Maybe by hovering over the element and by waiting for a few seconds? Something like: https://codeburst.io/css-tips-and-tricks-using-pseudo-class-fa83248bb6e0 I'm just thinking out loud. I know that it is easy to disable AOS but in this case I was not even aware of the core features so I could not tell them apart. Link to comment Share on other sites More sharing options...
tpr Posted February 27, 2019 Share Posted February 27, 2019 It would possible of course but I'm not sure that would be too beneficial. It would further increase the DOM weight and make more clutter, even when it could be disabled. Furthermore, many features couldn't have such indicators (eg. hotkeys) and it would be hard to create a "trademark" that would fit for most feature. But PR's are welcomed, as always ? 1 Link to comment Share on other sites More sharing options...
Leftfield Posted May 28 Share Posted May 28 @kixethat's a great solution!!! But, reducing database queries is a priority for me. So, here's a straightforward approach to prevent bloating: Example: I use a button with descriptions on various parts of the different pages. I needed a simple solution to change everything in one place, not to edit every page. So I made global-button.php (and more similar files for the same purpose) and called it wherever it needed to be with <?php include('global-button.php'); ?> So now I have only one page to edit, and voila. Hope this will help someone. 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