29

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 %} {# Loop through all of the site locales, except the current one #} {% set otherLocales = craft.i18n.getSiteLocaleIds()|without(craft.locale) %} {% for ...


21

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 translation. If you would prefer to output the locale’s name in its native tongue, use nativeName instead: {{ locale.nativeName }} You can also output the name of ...


15

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 "current" class: To assign the current locale's link a class of "current", compare the looped locale to the current locale and set a variable that you can later test ...


14

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: Impossible to access an attribute ("locale") on a NULL variable ("") The expanded if-statement looks now like this: {% if localeEntry.locale is defined and ...


14

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). So {{now|date('F j, Y')}} will give July 13, 2014 on the English site, and luglio 13, 2014 on the Italian site. Which is half way there. In order to get the ...


12

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 having to change settings in the admin panel by simply using an absolute path in the Admin assets source URL setting (i.e. /assets/img/uploads) and a relative ...


12

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 all available sites for an entry with {% set supportedSites = entry.getSupportedSites %} This will return you an array of all supported sites for the entry. {...


10

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.


10

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() %} {% for locale in locales %} {% set entryURL = craft.config.siteUrl[locale.id] %} {% if entry is defined %} {% set ...


10

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 template as per http://buildwithcraft.com/docs/templating-overview#template-localization


9

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 (you can also link templates to them) and created my site navigation like in my example code below. This allows you to translate the slug of the index pages in ...


9

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 full paths for your Asset definitions. You'll need definitions for both the file system path and URL path. Let's name them appropriately so we don't get ...


9

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 separate template to include in each page: {% if entry is not defined %} {% set entry = null %} {% endif %} <ul> <li><a href="{{ craft....


9

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. So in your case you could do this: {{ "Leer esta página en Español"|t(language="es") }}


8

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. Since Yii ships with so many locales, we initially stripped a lot of them out to keep the Craft download size to something reasonable. If there are some locales we ...


8

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 elements: Each element (entries, assets, users, etc.) which can be translated has a locale-column: UPDATE craft_categorygroups_i18n SET locale = 'en' WHERE locale =...


8

"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 difference is that a "site" isn't necessarily tied to a language code, like it is in Craft 2. https://craftcms.com/news/craft-3-multi-site Update: ...


8

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'), '@baseUrl' => getenv('CRAFTENV_BASE_URL'), ], (or whatever/however you want to set them). These aliases can be used in sites’ Base URL settings, ...


7

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


7

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 }} Update. If there is any chance that the entry/section is disabled for that locale you can also check it first, like so. {% set nlEntry = craft.entries.id([entry....


7

Untested, but should be fairly straightforward. {% if craft.locale == 'de' %} {% set template = '_layout_de.html' %} {% else %} {% set template = '_layout.html' %} {% endif %} {% extends template %} or {% extends craft.locale == 'de' ? '_layout_de.html' : '_layout.html' %} or using a locale folder (thank josh baker) {% extends craft.locale ~ '/...


7

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 Craft's static text translation feature by hard coding the strings you want to translate in a translations file (e.g. /translations/en.php). An example: If one ...


6

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 know which strings are missing translations and which translations are no longer in use. Old: We currently have our own command line tool that goes through all ...


6

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 tags = craft.tags.relatedTo({ sourceElement: entries, sourceLocale: craft.locale }) %} With the addition of order('dateCreated desc').limit(10) ...


6

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 a Matrix as translatable causes the base problem here, that the set of elements in an original language isn't copying at all into other Locales, as would be ...


6

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/js/scripts.js"></script> The only disadvantage of that is it makes your site slightly less portable – you wouldn’t be able to run it from a ...


6

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 .htaccess included a RewriteBase, which was set to /. So when one tried to access /no/{slug} the RewriteBase would send it up one folder, basically. So I had to ...


6

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 you have any complex fields (like custom field types), they may or may not export/import easily. I would also strongly consider giving your translator ...


6

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 files you must add each of those names along with the long form name. languages => array( 'es_pn' => 'Panama', 'es_co' => 'Costarica', 'en_nc' => ...


6

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',


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