Jump to content

Weird behaviors with Processwire Site Translation Files / Code Internalization


Recommended Posts

Hi Guys

I have a problem with the Code Internationalization (Site Translation Files) in Processwire. I am using the method Ryan is describing in this topic and also the normal way of translating files. The weird behaviors are that translations are just gone after a change in the main translation file called _strings (uses Ryan method). Or some other weird behavior was, that the english translation of the _strings file were somehow ported inside the german _strings file. I really don't know what could cause this. Have ever witnessed something like that? 

I have made some thoughts about this whole Code Internalization thing in ProcessWire and I am thinking to go another way (don't get me wrong, it's perfect for small to mid projects but in my opinion it is just a overkill for big projects), because at the beginning the strings we needed to translate were splitted up in many files which produced many site translation files to translate per language. It was just to much and confusing for the customer (and also for me), so that we needed another approach. So I tried Ryans method with one central translation files. The problem with this one is that it also gets confusing since it is a very big amount of strings to translate and also the problems described above. So for know I will try to make approach to store the strings in Pages. All translations of a string would be stored side by side. I know that this is probably more complex behind the scenes but it is far easier for the customer (especially with ListerPro). And I also like the idea of having the translations inside the DB instead in form of Files.

What are your thoughts about it? Have ever done something like that?



Link to comment
Share on other sites

I tried to make a function, which I can fetch translations from a page by it's name field.

Features of the function:

  • Fetches translations from page title (multilanguage).
  • Outputs an edit link to the Translation Page (doesn't output it when 2nd argument is false)
  • When the translation page you are referencing is not found, it outputs an error and also the absolute path to the php file were the function was executed by using debug_backtrace function of PHP.

Benefits of this approach:

  • You have full access to the ProcessWire API in terms of manipulating the translation data
  • Translations of single Strings in different languages are side by side (tabs)
  • Searching of single Translations is easy with Listers (I know search of site translation files is supported in PW3 but not in PW2, and I am using PW 2.7.3)
  • Usability is far better since the users doesn't have to fiddle around in the system languages itself.

Possible disadvantages:

  • Little overhead when using the function, since it always loads a page behind the scenes when the function is used. (I had used 8-13 function calls inside a template file and doesn't had noticed any performance issues (bless processwire)).
function _gt($key, $edit = TRUE){
    $link = "";
    $tracemessage = "";
    $string = "";

    $translationPage = wire('pages')->get("template=translation, name=$key");
      if($edit && wire('user')->isLoggedin()){
          $editlink = " <a style='color:green;' target='_blank' href='".$translationPage->editUrl()."'>[Edit]</a>";
      $string = $translationPage->title.$editlink;
        $trace = debug_backtrace();
        $tracemessage = "(".$trace[0]["file"].")";
      $string = "<span style='color:white;background-color:red;padding:5px;'>[Not Found: '".$key."'] $tracemessage</span>";

    return $string;



echo _gt("akkreditierung");
echo _gt("fachgebiete-doctor");



And when it fails to find the translation page:


Edited by Nukro
Function Rewrite, better explanation of use
Link to comment
Share on other sites

I am quite happy with translation options included in PW.

Translatable strings like

$out = $this->_("Live long and prosper");  // syntax within a class (modules)
$out = __("Live long and prosper!"); // syntax outside of a class (templates)

are useful for modules and (rarely) in the template system.

To make them accesible globally I define a page property in my _init.php file which is prepended to each template.

 * define globally used translatable strings here
$page->__read_more = __('
$page->__submit = __('Submit');


Furthermore I use some language related functions (language specific date and time formats). These functions are placed in _func.inc which is included by the _init.php

// Include shared functions

Everything else is content and should be stored in multilanguage fields. (text, textarea, optionselect)

  • Like 3
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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By donatas
      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)
      $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
      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 Cyber-mano
      Hi everybody,
      First time for me here to ask an help. So I apologize in advance for any section mistakes or forum rules not respected.
      I'm a newbie in PW, only 1 year working on it.
      I have a page with Date/Time pickers and they work perfectly, but I should have those in Italian (for safe editors that aren't so good with English).
      So I followed the translation suggestions founded in some old posts.
      Once setted the correct URL, the DatePicker are displayed in the right language, but I have an error on page saving: it seems that the field doesn't register the date/time change from the older language. The same problem occurs if I create a new page, not only changing the old ones.
      May I have missed something?
      Thanks a lot in advance.
    • 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?
    • By gerritvanaaken
      Wouldn’t it be cool to have whole repeater items (or even repeater matrix items) language-specific. Some of my clients do have pages that are 90% identical in German and English, but there are some sections that should not appear in one or another language. I attached a concept screenshot.
      Would something like this be possible with some simple backend hooks and "hidden checkbox fields"? Or is it way more complicated?

  • Create New...