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 ...
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 "...
  • 35.9k
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 ...
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). ...
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: ...
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 ...
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() %} ...
  • 301
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 }} ...
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. ...
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 ...
  • 23.6k
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 (...
  • 35.9k
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. ...
  • 66.5k
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 ...
  • 8,326
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 ...
  • 66.5k
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'), ...
  • 11.1k
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/
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 ...
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 ...
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 ...
  • 66.5k
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 ...
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 ...
  • 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/...
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 ....
  • 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 ...
  • 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 ...
  • 2,717
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',
6 votes
Accepted

Override admin local name

You can add your own translations by placing a region-specific translation file in a craft/translations folder. The filename should be named after your locale and return an array of translations. In ...
  • 13.3k
6 votes
Accepted

Scaling channels with 35 locales

You could have a single News section that is enabled for each of the locales, and choose which locale each entry should target from their Edit pages. To make it easer on the authors, you can set the ...
6 votes
Accepted

Craft 3 Multi-site with no "default" site

This can be done in 3 main steps. 1. Get the site subdirectories working First just get the /en/ and /es/ subdirectory working: Create en/ and es/ subfolders in your webroot Each subfolder should ...
6 votes
Accepted

What is the difference between the Translation Methods when creating a new site

Not translatable The field will always have the same value for each site Translate for each site Easy: the field can have a different value for each of your sites. Create 10 sites, all can have ...

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