Sign in to follow this  
Followers 0
Marcel Stäheli

Using name-field on multi language site

4 posts in this topic


if have a few article pages that have a multi-page reference field with tags about the content of the article. All tags of a given page are displayed and link to a tag-overview page.

Every link has a query string added with the tag name like &tag=cars so that I know which articles have to be displayed on the tag-overview page,
The tag name is created using $tag->name. Since the website is multi language using German (default) and English, I use $page->localName($language) to get the localized page name . The code looks like this:

foreach($tags as $tag) {        
    $tagsMarkup .= "<a  href='" .
                    wire('pages')->get('/tags-overview/')->url . 
                    "?tag=" . $tag->localName(wire('user')->language) . 
                    "'>" .  $tag->title . "</a>, ";

The code works mostly fine, but when a page has the same name in both languages, the query string will have no value just ?tag=. Why?


A second problem that might be tied to the first:
Once on that tags-overview page, I check if the tag actually exists using:

$allTags = $pages->get("/tags/")->children);

if($allTags->has("name=$tag") {...}

But as I read on the forum ( that only checks for name in the default language. It was suggested to use $page->parent->path . "pageNameEnglish" but I'm not sure where and how to use it in my case.

Any help?


Share this post

Link to post
Share on other sites

Hi @Marcel Stäheli

For the first question:

Just tested and it works as expected in my installation.

For the second: 

What is the purpose of this kind of check? 



Share this post

Link to post
Share on other sites

@Zeka Thanks for testing it. I was not precise enough. It works with the default language German. But when I switch to English the query string of a page with the same name in both languages is &tag=. Did you check in both languages?

Second question: It is meant as a security check. I noticed that should someone enter a query string manually like &tag=a I get all kinds of pages listed. So I make sure that the tag actually exists. There are probably better ways to do this. But I would still be interested to know what would be the easiest way to use find() to search for name-field values in the current language?

Share this post

Link to post
Share on other sites

@Marcel Stäheli Actually I checked whether I get value from $page->localName($user->langauge); I checked it in three languages and even with activating/deactivating it in page settings. So even if a page is not active for the current language I still got language specific name.


Why not use

$tagName = $sanitizer->name($tag)

if($pages->get("/tags/{$tagName}"}->id) {

If I'm not mistaken it looks for in all languages. 


Share this post

Link to post
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
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Fuad Ibrahimov
      Hi all!
      I have a problem with selecting default language in frontend.
      I tried to set default language from admin panel in Access->Users for guests and admin to another language, but it changed only backend language.
      I read a lot of topics about this problem and i didn't find any normal solution.
    • By heldercervantes
      I've had this happen before, but now I got this problem again and I'm wondering what it's about.
      I use the basic <?= __('Contacte-nos') ?> method for adding translatable text to templates. Some of these are not appearing on the form when I edit the file's translations in PW.
      Take this line of code:
      <?= __('1 ou +7 pessoas?') ?> <a href="#" class="contactsMenu"><?= __('Contacte-nos') ?></a> The first string "1 ou +7 pessoas?" appears when I edit the translations, but the second one doesn't. Eventually I figured out I can only have one of these per line of code. Adding a line break somewhere somewhere between them was enough to make both translations show up in the form.
      Problem solved, but curiosity remains. What is the reason for this?
    • By Kemal
      I am creating Multilanguage site for my customer. One of the languge is Arabic.
      What should i do for arabic language support?
      i installed multilanguage profile but when i type arabic language characters its not seen in url part. 
      Its empty and when i hit the save button it become default url (english)
      I tried to modify inputfieldpagename.module  file but its not working. It only translating the foreign character to latin character
    • By gebeer
      I am building a dynamic frontend form from fields of a page, following Soma's great gist example.
      The form is working fine, except for multi language values.
      After this part of the code
      $form->processInput($this->input->post) when I loop over the form fields, I don't know how to access the multi language values of a field
      foreach($form as $field) { // how to get multi lang values here } What I tried is not working
      foreach($form as $field) { if($field->type instanceof FieldtypeLanguageInterface) { foreach ($languages as $lang) { $langval = $editpage->$field->getLanguageValue($lang); $editpage->$field->setLanguageValue($lang, $langval); } } else { $editpage->set($field->name, $field->value); } }  Actually the $field->type returns just "text" for a PageTitleLanguage field.
      var_dumping the $field reveals that the language values are stored deep inside the object like
      'value1023' => string 'Testworkshop2' (length=13) 'value1032' => string 'Testworkshop2 Englisch' (length=22) So how would I access those other than pulling them directly from $this->input->post?
    • By gebeer
      I would like to find all fields that are multi-language.
      My code
      $langFields = new FieldsArray; foreach ($fields as $f) { if($f->type instanceof FieldtypePageTitleLanguage || $f->type instanceof FieldtypeTextareaLanguage || $f->type instanceof FieldtypeTextLanguage) { $langFields->add($f); } } Is there a more generic way of how I can determine whether a field is multi language, other than checking  "$f->type instanceof" for all three fieldtypes?