You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
lib/src/i18n/template/locale.ts

31 lines
959 B

import {Template} from '../../cli'
import {Container} from '../../di'
import {Config} from '../../service/Config'
/**
* CLI template that generates a new locale file.
* Automatically adds placeholder entries for phrases that exist in the
* associated common locale file.
*/
const templateLocale: Template = {
name: 'locale',
fileSuffix: '.config.ts',
description: 'Create a new config file that specifies translations for a locale.',
baseAppPath: ['configs', 'lang'],
render: (name: string, fullCanonicalName: string) => {
const config = <Config> Container.getContainer().make(Config)
const subloc = fullCanonicalName.split(':').slice(1)
.join(':')
const common: any = config.get(`lang:common${subloc ? ':' + subloc : ''}`, {})
return `import {env} from '@extollo/lib'
export default {
${Object.keys(common).map(key => ' ' + key + ': \'\',\n')}
}
`
},
}
export { templateLocale }