In developing multilingual websites, I've created a way to toggle between languages on each page of the sites.
Here is a way to create a bilingual website. The key to this technique is to:
-
Create two different single-language sites within a single nation, each with a custom theme where you have translated the text inside the theme files.
-
Synchronize the slugs of the pages with the different languages you plan to use.
-
Add a simple "language toggle" (or a button where you can switch between the different languages) to your front facing website.
You can use your nation's main website as the version of the site in your preferred language. These directions assume your preferred language is English, but the instructions work for any preferred language.
First create a custom theme. Even if you don’t intend to customize your theme, you need to create a custom theme in order to add the language toggle to the front facing site. The easiest way to create a custom theme is to select a theme that you already like and then clone it.
Under Website > Theme, choose “New custom theme” and have it clone your current theme.
Do all of the customization that you want to the theme. Any changes you make after you clone this theme and start translating it will be twice as much work so I recommend you go crazy now.
One bit of customization to do now: adding the language toggle. You can put the language toggle wherever you like on your front facing website. Below, I am showing how to put it into the main top navigation of your website.
Within Theme > Templates , find:
“_nav.html” and edit it.
Just before...
</ul> </nav>
lines and just after
{% endfor %}
...insert this code:
<li class="nodrop">
<a href="http://FrenchVersionOfYourSite.nationbuilder.com{{ page.url }}">Français</a>
</li>
The important thing here is the HTML href attribute - this is telling the English site that you want a link it to the same page on the French site.
The first part of that href should be replaced with the actual host/domain name of the French version of your site. Within you nation, it will be the website slug followed by a hyphen followed by your nation name.
Example:
<a href= "http://FrenchVersionOfYourSite.nationbuilder.com{{ page.url }}">French</a>
If you’re using a custom domain, check out this helpful FAQ and decide whether to use two different domain names or two subdomains of the same domain.
The second part of the url is {{ page.url }}. This is a variable that will contain a forward slash and the slug of that page. If you assign the same slug to the same content in different languages, then someone following that link should go to the corresponding page in the other language.
Now would be a good time to edit:
page_not_found.html template under Current custom theme > Templates
Just to make sure that people who follow a language change link to a missing page can find their way again.
When your theme is the way you like it, it’s time to create a new site, of the same type as the first one. In this case I am creating a French site. Go to Website > +Add new site.
Once the site is created, switch your French site to the custom theme we just finished creating. Click on “Switch to a custom theme” and select the theme of the English site.
We don’t want the two sites to have the same theme, we are just using the English theme as a starting point. Immediately click on “New custom theme” before you edit anything, and clone that English theme and call it a French theme.
Now comes to all translating we need to do.
Under “Templates”, “Email autoresponses” and “Email notifications” there are many different files. Examine them one by one for text, which will mostly show up in white in NationBuilder’s built-in editor. In actual fact the majority of files don’t have any text that needs translating, or won’t be used in your site, but it’s worth the extra minutes to check them all.
Pro tip: you can carefully use the machine translation engines of Google or Bing on the entire file. These engines will generally preserve the html code, but they do a poor job preserving the Liquid syntax, the things in curly brackets. Anything in curly brackets will have to go back to the way it was originally.
Start with the “_nav.html” file and make this site’s copy of the language switch that you had inserted in the other theme’s template point back to the English site by changing the domain name and the name of the language.
Next, edit the “layout.html” file. In the “<html” tag, change
xml:lang="en" lang="en"
from “en” to the standard language code for your language. If the lang attributes aren’t there, add them. This will change the language of the Twitter widgets -- the Twitter FAQ lists currently supported language codes. It will also allow you to use the :lang(nn) pseudo-class in css style sheets.
In the same file, change
{{ content_for_footer }}
to
{{ content_for_footer | replace: 'en_US', 'nn_NN' }}
Where nn_NN is the supported Facebook locale. Facebook maintains a Facebook Locales XML file listing supported locales.
Next, go to Website > Pages and check every page that is there, to provide translations for the pages that you want to keep.
For each of the pages, go through:
- Settings – Page settings:
- Change the Name, Title, Headline, tags
- Do NOT change the slug
- Reformat the date to the right language
- For the ones that have subpages, repeat for subpages
- Some page types have extra settings that sometimes contain text
Settings – SEO:
- Change the Title, Headline, Excerpt (if not already done)
- Do NOT change the slug
- Settings – Social media:
- Change the Default post (if not already done)
Content:
- Change Content and excerpt
Later, when you create new pages on the English site, you will have to go through a similar process to recreate similar pages on the new site, remembering that the slug on the different language version should be the same. However, unlike the theme files, pages are not copied over automatically.
If your original site already has some content and you want to copy the site’s content as well as the theme, then before you create the second language site, on the English site go to
Site settings > Sharing, check “Share this site”
Then fill in the name of the site (for your reference), a short description, and enter your own nation’s name under “Share with nation." When you create a new site for the other language as we did above, select the custom site type you just created.
For the control panel, you can change the default language by going to Settings > Defaults > Basic, but this affects the entire nation, not just one web site or person.
Other things to consider: you will also have to determine whether you want to have one or two broadcasters, whether to connect them to the same Facebook and Twitter accounts or separate ones, whether to make bilingual posts on social media or separate ones, and whether to tag people according to the language of the site they interacted with.
You should be well on your way to creating a multilingual nation!
Showing 31 reactions
Sign in with
Film and Campaign Ltd.
Certified Architect
Have never done this. If anyone has, ideally a native speaker, please do get in touch.
Hines Digital
Certified Architect
Certified Expert
Film and Campaign Ltd.
Certified Architect
Hines Digital
Certified Architect
Certified Expert
Check by cStreet - Mobile event check-in for organizers
Certified Architect
Certified Developer
Hines Digital
Certified Architect
Certified Expert
I just made one for a client in French & English, and I actually went another route from what we’ve discussed here and made two “mirrored” themes (one in each language). It was a lot of work, but I edited every single form label, etc., in the French one and it is dead-on.
Certified Architect
Hines Digital
Certified Architect
Certified Expert
If NationBuilder is making progress on better internationalization support in stock themes, I’d think that would be far, far better all around.
Certified Architect
Hines Digital
Certified Architect
Certified Expert
The idea would be that I’d edit each page template (both the 1col and 2col versions) and create two or more variations to the page, one for each language. I’d control for the “language” by using two character language code as the site’s “slug.”
So if you changed the site’s “slug” to “fr” — all the page templates would appear in French. “ES” would make them appear in Spanish. Etc.
Hines Digital
Certified Architect
Certified Expert
What I ended up doing was designing the whole, theme, then cloning it, and ultimately translating everything in the theme into French. I’m not referring to content — I’m referring to all the form labels, etc.
The crazy-go-nuts approach to making this forward compatible would be to carefully go through the whole base theme (Aware, Foundation, whatever) and make all the form labels conditional on the site.slug. So:
{% if site.slug == “fr” }French Label { elsif site.slug == “es” }Spanish Label{ else }English label{ endif %}
That would be a TON of work, but you’d only need to do it once (more or less).
Certified Architect
Certified Architect
One issue with a shared theme without breaking the child’s pages off the parent theme is translating page template code on vital elements like forms that may appear multiple times and custom fields would be another mess. But it’s still probably easier than maintaining two completely separate themes.
But another issue is that, over LibArt’s 8 years, in every case but one, campaigns and NPOs have not had the resources to translate entire sites. That includes extremely well funded Senate and Gubernatorials. There just isn’t usually staff or time to maintain a fully mirrored site.
For our projects, it’s always followed the model of a main language and a micro(s) for secondary language(s). Obviously that would be different in a region with 2 official languages or laws requiring full duplication (as with the one time we actually did full duplication), but trying to maintain all the pages in multiple languages is a promise that likely can’t be kept. Even when starting out attempting to duplicate an entire site, it’s always ended up with our client deciding to scale back to just key pages by launch.
Hines Digital
Certified Architect
Certified Expert
One thing that’s come up for me is that folks will want the page slugs to be in the native language for the site they’re on (i.e., meet_the_team rencontrer_lequipe). In that case, you’d probably want to create redirect pages to manage that redirection in a way that still works with your page.url trick (which is awesome).
Thanks for writing this up!