I write my blog in two languages. But they’re just two builds of the same DocPad installation with different settings.
You can use this blog’s source code as an example of this technique. Below I’ll describe all necessary steps to translate your blog’s content and user interface.
Translating posts
Create separate folders for each language’s blog content. In my case it’s src/documents_en and src/documents_ru (for English and Russian correspondingly).
Then add this code to your DocPad config (docpad.coffee):
Now you can run or generate blog in desired language:
Translating unser interface
Create YAML files for every language.
For example, src/lang/en.yml:
You can add here all the data you want to translate.
You’ll also need few helper functions, so add them to DocPad config file:
Install libraries used in above code from npm:
You can find plural functions for you language in polyglot.js.
Now you need to replace all local specific data in your templates with this helpers.
Regular strings:
Plurals:
And dates:
Language switcher
Add few lines to your YAML files:
And few to docpad.coffee:
Add a link to a template:
Server configuration
The last thing you need is to point your server to the right folders with published files. I use different hosts for each language but you could use subfolders but it’s beyond the scope of this blog post.