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