First pass at implementing site locales and translations #131
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Partially addresses #49
This PR adds two new concepts to Bridgetown:
available_locales
key to your config to list one or more locales (en, fr, zh, etc.) OOTB it's "en". Bridgetown will configure the I18n gem with those locales and to look for YAML files insrc/_locales
, so you can add translation files just like you would in a Rails app.BRIDGETOWN_LOCALE
environment variable if present or thedefault_locale
config key. You can access this value in templates viasite.locale
, and in Ruby code (plugins, etc.) you can switch the current site locale viasite.locale = :de
.It also adds a
t
helper for ERB/etc. templates and at
Liquid tag. The Liquid tag is currently very basic so it doesn't support default values, interpolation, etc. The ERB/etc. helper just aliasesI18n.t
so you get the full power of that method.I think this is a good start to adding multilingual site support. Theoretically, just this functionality could let you write a script to build a site multiple times, each with a different
BRIDGETOWN_LOCALE
env var and destination folder, and then you'd get multiple sites that have different translations for the same URLs that you could host onen.domain.com
,fr.domain.com
, etc.I suspect many people though (including myself) want the
domain.com/foo
,domain.com/fr/foo
,domain.com/zh/foo
approach, so that would still require additional work in another PR(s) so that all languages are processed through a single build process.