Skip to content
This repository has been archived by the owner on Apr 20, 2018. It is now read-only.

Provide option to merge translations #11

Open
4 tasks
alexlafroscia opened this issue Mar 22, 2017 · 0 comments
Open
4 tasks

Provide option to merge translations #11

alexlafroscia opened this issue Mar 22, 2017 · 0 comments

Comments

@alexlafroscia
Copy link
Collaborator

alexlafroscia commented Mar 22, 2017

In order to keep translations small, I've been providing only differences from English in my translation files, and then having all locales fall back to the en-US translation file if nothing else can be found.

It would be cool to allow this to be generated automatically through a config option, like:

yo skatejs:translation fr-CA --fallback fr-FR,en-US

or something similar, to do the following in the Translation helper automatically

import enUS from 'whereever';
import frFR from 'whereever';
import frCA from 'whereever';

const translationMap = new Map();
...
translationMap.set('fr-CA', merge(enUS, frFR, frCA));

where merge is like Object.assign except that it supports deep merging of keys with an object for a value. My personal implementation uses deepmerge, which might be an appropriate initial approach.

  • Provide fallback option that allows a locale to fall back to other arbitrary locales
    • Fail if a fallback locale does not exist
  • Automatically install deepmerge and set up the merge function the first time only
  • When the fallback option is provided, generate the map's value by merging locales instead of simply using the imported file
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant