Feature request: basic i18n support #269

Open
kristoferjoseph opened this Issue Mar 6, 2014 · 8 comments

Projects

None yet

7 participants

@kristoferjoseph

Add basic i18n support

First off, loving Harp!
Been wanting to add i18n support to my static html files and think I've come up with a simple way, but would like your feedback. If you can give me some pointers on how I will gladly add this to harp via a PR.

Proposal:

add a data directory with nested locale directories:

Input

myHarpProject/
| data/
| | en/
| | | _data.json => { "title": "Welcome" }
| | gb/
| | | _data.json => { "title": "Willkommen" }
| _layout.ejs
| _harp.json <= could be overridden by locale variables?
| index.ejs

Compiling the static site would output multiple versions of the pages nested in locale folders

Output

myHarpProject/
| en/
| | index.html
| gb/
| | index.html

Questions

Is this something you would want added to harp?
Should these locale variables override the harp.json values?

@cfjedimaster
@kristoferjoseph

The JSON files are separated to avoid merge conflicts when committing to version control. This also allows people to crowd/out-source individual files for a specific locale. Ran into some issues using the single translation file you are recommending.
I imagined that the defaults would be specified in the harp.json file similar to how explicit layouts are done.

@cfjedimaster
@kennethormandy
Collaborator

I would love to see this. Abstracting the UI labels away from other content, knowing your static app can work with multiple languages even if you don’t need that out of the gate, maybe compiling different versions for different Cordova apps—there’s lots of stuff it would be valuable for.

I don’t know much about conventions in this area, so I can’t really speak to the specifics you’ve suggested. What I have seen before uses different files for the reasons you described, so that makes sense to me. I also think the _data.json over-writing the harp.json is what we’d want, that follows the existing convention of Harp.

It’s also worth nothing that we might want to allow data.json as well as _data.json: #196

Thanks for writing this up! What do you think, @sintaxi?

@tobinharris

+1 for this.

@AlvarezAriel

This looks like a really nice feature.
What is the status?

@thomaslove

There's a really great i18n project I used in a different project called i18n-node that could be used for translations perhaps? They way they lay their json files out works very well. Could be a source of inspiration? https://github.com/mashpie/i18n-node

@B7th
B7th commented Apr 23, 2016 edited

+1, but instead of separating it in different folder, probably a naming convention like _data.en.json would do the trick.

Also, would it be possible to read .yml as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment