This is just a bare-bones demo gatsby starter with the minimum required to demonstrate using ttag for precompiled internationalization with gatsby.
Developing or building in either English or Spanish is accomplished by passing
the environment variable LOCALE
to the respective gatsby commands.
These are added as scripts in the packages.json
for convenience:
{
"scripts": {
"build:en": "LOCALE=en gatsby build",
"develop:en": "LOCALE=en gatsby develop",
"build:es": "LOCALE=es gatsby build",
"develop:es": "LOCALE=es gatsby develop"
}
}
Precompiling is then handeled by the babel-plugin-ttag
babel plugin, using process.env.LOCALE
to pass build-time information to the babel configuration. The babel.config.js
is shown here:
module.exports = {
"presets": [
[
"babel-preset-gatsby",
],
],
"plugins": [
[
"babel-plugin-ttag",
{
"resolve": {
"translations": process.env.LOCALE === "es" ? "es.po" : "default",
},
},
],
],
}