Clarity Posted September 2, 2021 Share Posted September 2, 2021 Hello everyone! I have _strings.php file which I need to use on entire site. It is included in _init.php file like that: include_once("{$config->paths->templates}_strings.php"); However, our site uses partially uses Wire Render Pattern (https://github.com/joyofpw/wire-render-pattern), which is why _strings.php isn't getting included to some files automatically. Can you please tell us what to do in this case? Link to comment Share on other sites More sharing options...
horst Posted September 2, 2021 Share Posted September 2, 2021 What does it contain, whats in the _strings.php? What does it provide? (functions, vars, ...?) Maybe another method than include_once() could be more straight forward and also works with wire-render-pattern. 1 Link to comment Share on other sites More sharing options...
Clarity Posted September 2, 2021 Author Share Posted September 2, 2021 _strings.php contains variables which are translations from one language to another (e.g. $var1 = __('Text 1')). I thought it is a standard ProcessWire file. 1 Link to comment Share on other sites More sharing options...
horst Posted September 2, 2021 Share Posted September 2, 2021 On 9/2/2021 at 4:46 PM, Clarity said: _strings.php contains variables which are translations from one language to another (e.g. $var1 = __('Text 1')). I thought it is a standard ProcessWire file. To be honest, I don't know if this is a standard processwire file. But with language files one can use it as follows: Instead of adding each string to an own variable, you can add a second parameter to all the language strings you use around in different template files or module files or where ever you need them: __('Text 1', '/path/to/your/_strings.php'); __('Text 2', '/path/to/your/_strings.php'); ... And instead of adding the '/path/to/your/_strings.php' as text all the time, I use a functions call for that. This way you do not have to include the file and can use it everywhere handled through the PW translations system, because you tell it that the current string is the same as a string in the centralized _strings.php In /site/init.php I define this function, that simply returns the path to my centralized translation file: /** * TRANSLATABLE STRINGS * Include translatable strings */ if(!function_exists('ProcessWire\mystrings')) { function mystrings() { return '/site/_strings.php'; // absolute URL or absolute filepath to the central translation file } } My _strings.php would look like this: <?php namespace ProcessWire; /** * TRANSLATABLE STRINGS * Define globally available translatable strings * * USAGE * * __('Lesen Sie mehr ...', mystrings()); * * The function mystrings() returns the textdomain of this file. * **/ ... __('Datenschutzerklärung'); __('Die Maße des Werks sind:'); __('Dieses Bild drucken!'); __('drucken'); ... __('Text 1'); __('Text 2'); ... __('Zurück zur Übersicht'); To sum up, this way I don't need to include a _strings.php and it also works every where. 4 1 Link to comment Share on other sites More sharing options...
Clarity Posted September 5, 2021 Author Share Posted September 5, 2021 Thank you very much! 1 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