Jump to content

Code Internationalization (i18n) doesn´t work within included php files


daniel_puehringer
 Share

Recommended Posts

Hey community,

first of all: I love this CMS! But unfortunately my Code Internationalization (i18n) doesn´t work within included php files:

I´m using the module Pro Fields Page Table, the regular Languages Support Module and no template caching. The website has 2 Languages (DE as default, EN as second language)

Problem:

Using

<?php echo(__('Test')); ?>

within /site/templates/home.php works without any problems and gets translated correctly
However using

<?php echo($this->_('Headline'));?>

within /site/templates/components/component.php does not work.

Note: using

<?php echo(__('Headline'));?>

in .../component.php throws an error and therefore cannot be used.

 

Example:

/site/templates/ce-includer.php (Template with the dynamic text-field 'filepath'):

include('components/'.$page->filepath);

this correclty includes the file "/site/templates/components/home-content.php"

Code in home-content.php:

<h1><?php echo($this->_('Headline'));?></h1>


Output for both pages (DE and EN version - the string was translated to "Headline DE" in german and "Headline EN" in english):

<h1>Headline</h1>

Does anyone know how to use Code Internationalization in such a szenario?

All the best and keep up the great work!
Daniel

Link to comment
Share on other sites

3 hours ago, daniel_puehringer said:

Hey community,

first of all: I love this CMS!

Welcome to ProcessWire and the forums @daniel_puehringer.

3 hours ago, daniel_puehringer said:
<?php echo($this->_('Headline'));?>

$this__() is only for use inside a class. 

3 hours ago, daniel_puehringer said:

Note: using

<?php echo(__('Headline'));?>

in .../component.php throws an error and therefore cannot be used.

Have you tried echo __('Headline')? According to the docs, the (__('Headine')) syntax is for use with the placeholder syntax (printf() or sprintf()). Not sure why it worked inside your home.php though. Maybe someone more knowledgeable will provide a better answer. Meanwhile, just in case you missed them, here are the internationalization docs.

https://processwire.com/docs/multi-language-support/code-i18n/

Edited by kongondo
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.
  • Similar Content

    • By donatas
      Hello,
      how would I do a multi-language website search with just a selector?
      I have many multi-lang fields and I want to do a search through all of them at once and through all of their language values.
      Is there a "selector way" of doing this? Maybe something like `title|title:de|title:it`? It seems I have seen this somewhere a long time ago but can't find in any documentation or forum search...
      Or the only way of doing it is by running separate searches for each language with output formatting off and then consolidating it all in one single results array?
      Because I still want to give users a result, even if it is in another language than current $user. Visitors mostly will be searching for specific terms that are very similar in all languages, but might be not used in one language version of a single page, for example. Or the user might not have switched language tohis prefered and did the search first, etc.. (many use cases in my situation)
      Example:
      $pages->find('title~='.$q) - maybe different operator is needed? /en/search/?q=visit = 1 results /it/search/?q=visit = 0 results Thanks for any advice!
    • By sebr
      Hello
      One of my customers needs to have his site translated by a publisher. He asks me if it is possible to create a role that could only edit the German version of the pages, without permission on the English version.
      I haven't found any permission related to this need, but maybe it's possible from a hook?
      Thank you for your help
       
    • By Crowdland Technology
      Hello everyone.
      I'm having some issues with Greek as default language, because the page name is not created automatically when enter the title of a new page. 
      Any chance to add support for it?
      I found this char mapping that might help on line 188
      https://github.com/elpak/Greeklish-permalink-wordpress/blob/master/greeklish-permalink/greeklish-permalinks.php
      Thank you!

       
      [EDIT]: A solution
      This was easier than we thought, we managed to find a solution by looking at how the sanitizer of page names works. 
      This is how the URL looks with this solution:
       
       
      For ProcessWire 3+ (what we tested) find Modules > Core > InputfieldPageName and under the “Character Replacements” Field you can add the mapping you would like.


      The replacement is not in the Core yet, so adding it for reference. The mapping is adjusted and simplified, and it follows the official Transliteration found here: https://en.wikipedia.org/wiki/Romanization_of_Greek
      α=a
      ά=a
      β=b
      γ=g
      δ=d
      ε=e
      έ=e
      ζ=z
      η=i
      ή=i
      θ=th
      ι=i
      ί=i
      κ=k
      λ=l
      μ=m
      ν=n
      ξ=x
      ο=o
      ό=o
      π=p
      ρ=r
      σ=s
      ς=s
      τ=t
      υ=y
      ύ=y
      ϋ=y
      φ=f
      χ=ch
      ψ=ps
      ω=o
      ώ=o
      Cheers to @PWaddict for also supplying an unofficial mapping and pointing us to the right direction 
      @ryan It would be great if this would be added to the Core sometime in the future and we can assist with further official mappings that are not present in this simplified version.
      Thank you!

      Cheers,
      Elissavet from CrowdLand
    • By MoritzLost
      Sorry for the convoluted title. I have a problem with Process modules that define a custom page using the page key through getModuleInfo (as demonstrated in this excellent tutorial by @bernhard). Those pages are created automatically when the module is installed. The problem is that the title of the page only gets set in the current language. That's not a problem if the current language (language of the superuser who is installing the module) is the default language; if it isn't, the Process page is missing a title in the default language. This has the very awkward effect that a user using the backend in the default language (or any other language) will see an empty entry in the setup menu:

      This screenshot comes from my Cache Control module which includes a Process page. Now I realize the description sounds obscure, but for us it's a common setup: We a multiple bilingual sites where the default language is German and the second language is English. While the clients use the CMS in German, as a developer I prefer the English interface, so whenever I install a Process module I get this problem.
      As a module author, is there a way to handle this situation? I guess it would be possible to use post-installation hooks or create the pages manually, but I very much prefer the declarative approach. The page title is already translatable (through the __ function), but of course at the time of installation there is no translation, and as far as I'm aware it's not possible to ship translations with a module so they are used automatically. Could this situation be handled better in the core? I would prefer if the module installation process would always set the title of the Process page in the default language, instead of the language of the current user.
    • By Noel Boss
      Hi everyone 🙌
      Is there a way to order the language tabs in the backend? Currently, they seem to be ordered based on the created date (or id?) …
      ( time passes … ⏰ 🚶‍♂️)
      Just answered my own question. One can reorder the languages in the page tree under admin » languages or directly in the DB » pages » template_id=54 » sord field.
      Anyone knows if there are side effects when moving the default language from sort 0 to somewhere higher?
×
×
  • Create New...