Jump to content

Is this thing on?


MarcC
 Share

Recommended Posts

I'm testing ProcessWIre's localization features, trying out fields like TextAreaLanguage and PageTitleLanguage. I've got them installed, assigned, and filled out. Now, how do I, for example, make Spanish-language fields show up on the public site for Spanish-language visitors?

It feels like a bit of a dumb question, but I swear I looked at the docs!

I thought it might be automatic detection based on a header string or something, but that hasn't worked for me. I don't know exactly what details to look for as this is my first time through. Thanks!

Link to comment
Share on other sites

You won't be redirected just like that. You know that Ryan wouldn't do something like that to us, remember, you're still in full control ;)

Now you have to use the available methods to take people to the correct url. My favourite is implementing a simple language switch, since I personally hate to be redirected to my browser's language without being asked. You would use $page->localUrl($language) for this. Check how to do it here https://processwire.com/api/multi-language-support/multi-language-urls/

I usually do something as simple as this:

foreach($languages as $lang) {
    $active = $user->language===$lang ? 'class="active"':'';
    echo "<li {$active}><a href='{$page->localUrl($lang)}'>{$lang->title}</a></li>";
}

--

For serving the language based on the browser language, you don't even need the language urls —and since I've never done it, I may be giving you a wrong info— Just detect the browser language http://www.paulund.co.uk/auto-detect-browser-language-in-php and switch the user language accordingly with:

$user->language = $language;

Of course, if you prefer, set up the URLs and make the redirect instead.

  • Like 1
Link to comment
Share on other sites

Thanks Diogo, I didn't know that was there. So I've enabled /es/. Should I now change my browser language and test to see if I am redirected?

To do that use my super awesome AutoDetect Language module! Does that automagically for you!

Sorry no link, writing from my iPad. :)

  • Like 2
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 abdus
      I'm trying to build a multilanguage website with Turkish as main and English as alternative language. I replaced hardcoded strings in template files and used built-in translation tools to translate template files. I'm using the functions ProcessWire provides:
      // using __() <?= __("There are no products to display.") ?> // or _x() <html lang="<?= echo _x('en', 'HTML language code'); ?>"> // Both works when I use _main.php When I disable auto including _main.php from config.php file, and move or rename _main.php to something else or use another file (other than  _main.php that comes with site-languages profile) for template specific markups, say markup/products.php like below, translations stop working.
      // config.php, disabled auto append // $config->appendTemplateFile = '_main.php'; // home.php include_once("./_main.php"); wireIncludeFile("./_main.php"); // TRANSLATION WORKS include_once("./_home.php"); // DOESNT WORK wireIncludeFile("markup/_main.php"); include_once("markup/_main.php"); // DOESNT WORK // NOTE: home.php and main.php has the same content, same permissions, same ownership I debugged the issue, and the reason, as ridiculous as it sounds, originates from using file other than _main.php. I searched the forums, google, but this seems like a unique issue. Is there anything I'm missing and how can I fix this, because I can't think of anything else after hours lost trying to find the underlying cause?
      Thanks in advance.
    • By Orkun
      I have set the right Datepicker translation file "/wire/modules/Jquery/JqueryUI/i18n/jquery.ui.datepicker-de.js".
      And change the code from:
      /* German initialisation for the jQuery UI date picker plugin. */ /* Written by Milian Wolff (mail@milianw.de). */ jQuery(function($){ $.datepicker.regional['de'] = { closeText: 'schließen', prevText: '<zurück', nextText: 'Vor>', currentText: 'heute', monthNames: ['Januar','Februar','März','April','Mai','Juni', 'Juli','August','September','Oktober','November','Dezember'], monthNamesShort: ['Jan','Feb','Mär','Apr','Mai','Jun', 'Jul','Aug','Sep','Okt','Nov','Dez'], dayNames: ['Sonntag','Montag','Dienstag','Mittwoch','Donnerstag','Freitag','Samstag'], dayNamesShort: ['So','Mo','Di','Mi','Do','Fr','Sa'], dayNamesMin: ['So','Mo','Di','Mi','Do','Fr','Sa'], weekHeader: 'KW', dateFormat: 'dd.mm.yy', firstDay: 1, isRTL: false, showMonthAfterYear: false, yearSuffix: ''}; $.datepicker.setDefaults($.datepicker.regional['de']); }); to:
      /* German initialisation for the jQuery UI date picker plugin. */ /* Written by Milian Wolff (mail@milianw.de). */ jQuery(function($){ $.datepicker.regional['de'] = { closeText: 'schließen', prevText: '<zurück', nextText: 'Vor>', currentText: 'heute', monthNames: ['Januar','Februar','März','April','Mai','Juni', 'Juli','August','September','Oktober','November','Dezember'], monthNamesShort: ['Jan','Feb','Mär','Apr','Mai','Jun', 'Jul','Aug','Sep','Okt','Nov','Dez'], dayNames: ['Sonntag','Montag','Dienstag','Mittwoch','Donnerstag','Freitag','Samstag'], dayNamesShort: ['So','Mo','Di','Mi','Do','Fr','Sa'], dayNamesMin: ['So','Mo','Di','Mi','Do','Fr','Sa'], weekHeader: 'KW', dateFormat: 'dd.mm.yy', firstDay: 1, isRTL: false, showMonthAfterYear: false, yearSuffix: ''}; $.datepicker.setDefaults($.datepicker.regional['de']); $.timepicker.regional['de'] = { timeText: 'Uhrzeit', hourText: 'Stunde', minuteText: 'Minute', secondText: 'Sekunde', millisecText: 'Millisekunde', timezoneText: 'Zeitzone', currentText: 'jetzt', closeText: 'schliessen', }; $.timepicker.setDefaults($.timepicker.regional['de']); }); But it only affects the date and not the time. What I'm missing?
    • By EvanFreyer
      Hey there,
      I have a problem with URL Segments and Umlauts in it. I want to grab the a segment of the url and use it as a parameter to find a something in Processwire. The problem is, that if I input an umlaut into the url, processwire immediately throws a 404 error page and I am not able to transform my inputs.
      Is there a way to get around that problem?
      Cheers,
      Evan
    • By jtherczeg
      The great latest localization enhancements for PW 2.5 raise some problems due to the multi-language site profile.
      I observed that when the site translation files are included in the core translation files language pack, they are unnecessarily uploaded to the Core Translation Files and I can delete them, but cannot move them to their appropriate location.
      As the translation files are distributed in one package, many of them downloaded directly from GitHub, it would be a smarter solution if the language pack uploader dispatched the site language files to the Site Translation Files section.
      It turned out in Ryan's answer on my GitHub issue report, that we cannot use these site translation files for monolingual sites, so it would be recommended if the language pack uploader detected the multilingual status and when it failed (due to monolingual site), it displayed a warning and did not upload the site language files.
    • By jtherczeg
      Heya, everybody!
      The Hungarian language pack for Processwire is on the way. I will post here about the stages of the translation process.
      Stay tuned!
×
×
  • Create New...