Last call to make your voice heard! Our 2022 Developer Survey closes in less than a week. Take survey.
29 votes
Accepted

How can I build a language switcher?

I am building my first multi-language site with Craft as well. This is from a thread over at Google+, so I didn't come up with this myself but it works very well: {% block locale__switch %} {# ...
user avatar
  • 490
21 votes
Accepted

How do I output the locale’s name?

You can get the current locale’s name via craft.i18n.getCurrentLocale(). {% set locale = craft.i18n.getCurrentLocale() %} {{ locale.name }} That will output the name using the current locale’s ...
user avatar
15 votes
Accepted

How do I create a locale dropdown to switch between languages?

This is because you loop through all but the current locales. Remove the without filter to loop them all. {% set otherLocales = craft.i18n.getSiteLocaleIds()|without(craft.locale) %} . Add "...
user avatar
  • 35.8k
15 votes
Accepted

Craft 3 language switcher

The concept of localization has changed in Craft 3, there are not only locales anymore - now you have different sites and site groups. Example without multisite - only different locals You can get ...
user avatar
14 votes

How can I build a language switcher?

I have changed the above code a little bit because it causes an error when I have for example a website with three active locales and an entry with only one or two active locales. The error is: ...
user avatar
14 votes
Accepted

Multilingual Dates where date format varies

Craft has extended Twig's date filter so that it translates the output (no documentation for this, but the code is in craft/app/etc/templating/twigextensions/CraftTwigExtension.php around line 152). ...
user avatar
12 votes

What accurately will set asset paths for multilingual sites?

If each locale uses the same TLD but uses a subfolder for localized content (i.e. example.com/en, example.com/de, etc.). You can move between development, staging, and production environments without ...
user avatar
10 votes
Accepted

What's that |t - filter for?

It's the short syntax for the translate filter. Set up a translation file as described in the docs and the string you apply that filter to is translated according to it.
user avatar
  • 35.8k
10 votes

How can I build a language switcher?

Thought I would share my language switcher, as it shows languages in their native name. <nav class="nav nav--locale"> <ul> {% set locales = craft.i18n.getSiteLocales() %} ...
user avatar
  • 301
10 votes
Accepted

Locale Switch not Affecting News Index Template

This Google+ thread may help: https://plus.google.com/116942350387086245334/posts/TBtR3XwuZGx Current options as per above thread: Create a Single for the News index template Create a localized ...
user avatar
10 votes
Accepted

Get locale entry.title in other languages

You can use the 'locale' and 'id' attributes in your query to request the same entry in another locale. {{ entry.title }}<br> {{ craft.entries.id([entry.id]).locale('nl_nl').first.title }} ...
user avatar
10 votes
Accepted

Can I choose a language for the translate filter?

Yes. You can see all of the arguments the |t filter supports by looking at the docs for Craft::t(), the function that |t maps to. Its $language argument defines the target language translation to use. ...
user avatar
9 votes

Multi-lingual site navigation made of singles, channels and structure

I have one main structure "pages" and got rid of all single sections. I also gave each channel's index page an entry in the structure (good for URL translation). Then I added some entry types to it (...
user avatar
  • 35.8k
9 votes
Accepted

What accurately will set asset paths for multilingual sites?

An answer that works is to make your own environment variables, setting those apart from language variables, and as needed for each of your multiple sites. Then you can use these variables to make ...
user avatar
  • 1,697
9 votes

How can I build a language switcher?

I've created a plugin which makes it incredibly easy to add language-switching links to your website... Language Link plugin for Craft CMS Standard Usage Add this to your _layout, or create a ...
user avatar
  • 23.6k
8 votes
Accepted

Can I change the list of available locales?

You can download the locales you want from https://github.com/yiisoft/yii/tree/master/framework/i18n/data and place in your craft/app/framework/i18n/data folder and they will show up as options. ...
user avatar
  • 66.4k
8 votes
Accepted

Converting existing content to a different locale

Currently it's not possible to edit a locale from the CP, which means you have to edit it directly in your db. Edit locale: UPDATE craft_locales SET locale = 'en' WHERE locale = 'en_us'; Edit ...
user avatar
  • 8,316
8 votes
Accepted

How to add locales in Craft 3

"Sites" in Craft 3 replaces the old "Locales" concept in Craft 2. There's not much documentation on them yet, but the setup process is virtually the same as it is in Craft 2 for locales. The main ...
user avatar
  • 66.4k
8 votes
Accepted

Craft 3: how can I set dynamic Base URL in sites setting?

So as of Craft CMS 3 RC7, they added a new alias() Twig function. So what you can do is something like this in your general.php: 'aliases' => [ '@basePath' => getenv('CRAFTENV_BASE_PATH'), ...
user avatar
  • 10.9k
7 votes
Accepted

Locale change based on geolocation

The mod_geoip2 Apache module with a redirect in .htaccess file. See: http://dev.maxmind.com/geoip/legacy/mod_geoip2/
user avatar
7 votes
Accepted

Can locales be used to switch layouts?

Untested, but should be fairly straightforward. {% if craft.locale == 'de' %} {% set template = '_layout_de.html' %} {% else %} {% set template = '_layout.html' %} {% endif %} {% extends ...
user avatar
7 votes
Accepted

Is there a way to have checkbox field labels translatable?

Short of hardcoding all these checkbox values and applying the translate tag on them That's actually the only way to translate field names, checkbox labels/values and whatnot: taking advantage of ...
user avatar
6 votes
Accepted

How to extract static messages from templates into translation files?

Update: For Craft 3, we use the Yii 2 Inspections plugin for PhpStorm to do this now. https://plugins.jetbrains.com/plugin/9400-yii2-inspections There is a translation inspection that will let you ...
user avatar
  • 66.4k
6 votes
Accepted

Show a list of recently used tags only from the current locale

Brandon at P&T was able to fill in the piece I was missing. He said: To only get tags that were related from a specific locale, you just need to specify that in your relatedTo param: {% set ...
user avatar
6 votes

How do I get Matrix elements to copy their content across language Locales?

Ok, in some conversation with Brandon which leaned this direction, I realized a different direction to temporarily solving most of this problem. It turns out that a root of the issues is that marking ...
user avatar
  • 1,697
6 votes
Accepted

Custom environment variable to main assets folder

The easiest way to do this would be to just use root-relative resource URLs: <link rel="stylesheet" type="text/css" href="/assets/css/styles.css"> <script type="text/javascript src="/assets/...
user avatar
6 votes
Accepted

Problems with channel and locales

Okay, so I found the answer. And the reason it wasn't working is because I've been using another .htaccess (a hybrid of h5bp and Craft) than the default that comes with the Craft download. And this ....
user avatar
  • 421
6 votes
Accepted

Export Craft Data

One way to handle this is by using the Export and Import tools by Bob Olde Hampsink. This will allow you to output the data to a CSV file, which you can hand off to the translator. Be wary though, if ...
user avatar
  • 23.6k
6 votes
Accepted

Multi Country website - Using locales is the best approach?

Yes you can do this by going to the craft/app/framework/i18n/data folder and copying the language file for each occurrence. You must give each a unique name es_pn, es_co, es_nc. Inside each of those ...
user avatar
  • 2,707
6 votes
Accepted

Adding new locale - hangs at Step 3 'ResaveAllElements'

You probably need to up Craft's internal memory limit, as well – the following should go into the array in your general.php configuration file: 'phpMaxMemoryLimit' => '1024M',
user avatar

Only top scored, non community-wiki answers of a minimum length are eligible