Use translation chains and merge repositories
masterYou can combine multiple repositories to search for translations in sequence.
- Chains (
type: :chain): Iterates through the list of repositories. If the first cannot find a translation, it asks the next. - Merge (
type: :merge): Similar to chains but optimizes speed by selecting and storing the first translation found at load time. Note: You must calldomain.reloadif the locale changes. - Loggers: You can add a logger to a chain to track missing translations. A lambda responding to
callcan be used as a callback.
# Chain
repos = [
FastGettext::TranslationRepository.build('new', path: '....'),
FastGettext::TranslationRepository.build('old', path: '....')
]
FastGettext.add_text_domain 'combined', type: :chain, chain: repos
# Merge
domain = FastGettext.add_text_domain 'combined', type: :merge, chain: repos
# If locale changes:
FastGettext.locale = 'de'
domain.reload
# Logger
repos = [
FastGettext::TranslationRepository.build('app', path: '....'),
FastGettext::TranslationRepository.build('logger', type: :logger, callback: ->(key_or_array_of_ids) { puts "Missing: #{key_or_array_of_ids}" }),
]
FastGettext.add_text_domain 'combined', type: :chain, chain: repos