Skip to content

Commit

Permalink
closes #110 and #111: i18nFormat not working, wrong dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
martinroob committed Nov 9, 2018
1 parent 49b528d commit 8a2b5a8
Show file tree
Hide file tree
Showing 15 changed files with 439 additions and 420 deletions.
3 changes: 0 additions & 3 deletions TODOs.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
TODOs
script extract-i18n wenn schon vorhanden, warnen
OK Bei Aufruf --languages=en,de kam 2x added configuration de to.. und 2x added build configuration...
OK angular-devkit peer version zu klein
Setzen i18n-format per "--i18n-format=xlf2" hat nicht funktioniert (Testfall angelegt, da funktioniert es)
388 changes: 388 additions & 0 deletions projects/tooling/Changelog.md

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions projects/tooling/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ This adds the required packages and configures everything for the default langua
There are some command line parameters available:
- `--project` add the tooling to a specific project in your workspace
- `--languages` the languages to be used (a comma separated list like `en,de,ru`)
- `--i18n-locale` set the locale used in your templates (default is first language or `en`)
- `--i18n-format` the format to be used (`xlf`, `xlf2` or `xmb`)
- `--i18nLocale` set the locale used in your templates (default is first language or `en`)
- `--i18nFormat` the format to be used (`xlf`, `xlf2` or `xmb`)

For example you can use the following

`ng add @ngx-i18nsupport/tooling --project=myproject --i18n-format=xlf2 --languages=en,de,ru`
`ng add @ngx-i18nsupport/tooling --project=myproject --i18nFormat=xlf2 --languages=en,de,ru`

## Add a new language (addLanguage)
In an already configured project you can add one or more additional languages by using
Expand Down
2 changes: 1 addition & 1 deletion projects/tooling/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ngx-i18nsupport/tooling",
"version": "1.0.0",
"version": "1.0.1",
"private": false,
"description": "Schematics to add the tooling to be used with the Angular 2 i18n workflow",
"schematics": "./schematics/src/collection.json",
Expand Down
14 changes: 7 additions & 7 deletions projects/tooling/src/schematics/src/addLanguage/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ function setupOptions(optionsFromCommandline: AddLanguageOptions, host: Tree, co
throw new SchematicsException(msg);
}
if (xliffmergeOptions.xliffmergeOptions.i18nFormat) {
options['i18n-format'] = xliffmergeOptions.xliffmergeOptions.i18nFormat;
options.i18nFormat = xliffmergeOptions.xliffmergeOptions.i18nFormat;
} else {
options['i18n-format'] = defaultI18nFormat;
options.i18nFormat = defaultI18nFormat;
}
if (xliffmergeOptions.xliffmergeOptions.srcDir) {
options.srcDir = xliffmergeOptions.xliffmergeOptions.srcDir;
Expand All @@ -130,9 +130,9 @@ function setupOptions(optionsFromCommandline: AddLanguageOptions, host: Tree, co
options.genDir = xliffmergeOptions.xliffmergeOptions.genDir;
}
if (xliffmergeOptions.xliffmergeOptions.defaultLanguage) {
options['i18n-locale'] = xliffmergeOptions.xliffmergeOptions.defaultLanguage;
options.i18nLocale = xliffmergeOptions.xliffmergeOptions.defaultLanguage;
} else {
options['i18n-locale'] = defaultI18nLocale;
options.i18nLocale = defaultI18nLocale;
}
if (optionsFromCommandline.language && optionsFromCommandline.languages) {
const msg = 'Only language as parameter or --languages can be used, not both.';
Expand All @@ -153,8 +153,8 @@ function setupOptions(optionsFromCommandline: AddLanguageOptions, host: Tree, co
context.logger.fatal(msg);
throw new SchematicsException(msg);
}
if (options.parsedLanguages.indexOf(options['i18n-locale']) >= 0) {
const msg = `Language "${options['i18n-locale']}" is already configured (as default language).`;
if (options.parsedLanguages.indexOf(options.i18nLocale) >= 0) {
const msg = `Language "${options.i18nLocale}" is already configured (as default language).`;
context.logger.fatal(msg);
throw new SchematicsException(msg);
}
Expand Down Expand Up @@ -185,7 +185,7 @@ export function addLanguage(optionsFromCommandline: AddLanguageOptions): Rule {
return (host: Tree, context: SchematicContext) => {
const options: OptionsAfterSetup = setupOptions(optionsFromCommandline, host, context);
const languagesToAdd = options.parsedLanguages
.filter(lang => lang !== options['i18n-locale']);
.filter(lang => lang !== options.i18nLocale);
const configurationAdditions = languagesToAdd
.map(lang => addLanguageConfigurationToProject(options, lang));
const startScriptAdditions = languagesToAdd
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ export function isValidLanguageSyntax(lang: string): boolean {
}

export function fullExtractScript(options: OptionsAfterSetup): string {
const defaultLanguage = options['i18n-locale'];
const i18nFormat = options['i18n-format'];
const defaultLanguage = options.i18nLocale;
const i18nFormat = options.i18nFormat;
const languagesBlankSeparated = options.languages ? options.languages.replace(/,/g, ' ') : '';
const languagesCommandLineArgument = (options.useComandlineForLanguages) ? ' ' + languagesBlankSeparated : '';
const localeDir = options.localePath;
Expand All @@ -42,7 +42,7 @@ export function buildConfigurationForLanguage(options: OptionsAfterSetup, langua
aot: true,
outputPath: `dist/${options.project}-${language}`,
i18nFile: `${options.genDir}/messages.${language}.xlf`,
i18nFormat: options['i18n-format'],
i18nFormat: options.i18nFormat,
i18nLocale: language
};
}
Expand Down
4 changes: 2 additions & 2 deletions projects/tooling/src/schematics/src/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ export const xliffmergePackage = '@ngx-i18nsupport/ngx-i18nsupport';
* This value will be written into package.json of the project that uses ng add.
* TODO must be changed for every new release.
*/
export const xliffmergeVersion = '^1.0.0';
export const xliffmergeVersion = '^1.0.1';

/**
* The default language (i18n-locale) when you do not specify anything.
* The default language (i18nLocale) when you do not specify anything.
*/
export const defaultI18nLocale = 'en';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ export interface OptionsAfterSetup {
localePath: string;
srcDir: string;
genDir: string;
'i18n-format': string; // the used format (xlf, xlf2, xmb)
'i18n-locale': string; // the default language
i18nFormat: string; // the used format (xlf, xlf2, xmb)
i18nLocale: string; // the default language
languages?: string; // languages given at command line as comma separated list
parsedLanguages: string[]; // languages given at command line plus default language
configuredLanguages: string[]; // languages that are already in the workspace
Expand Down
16 changes: 8 additions & 8 deletions projects/tooling/src/schematics/src/ng-add/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ function setupOptions(optionsFromCommandline: NgAddOptions, host: Tree, context:
optionsFromCommandline.useComandlineForLanguages
: false;
const languagesFromCommandline = (optionsFromCommandline.languages) ? optionsFromCommandline.languages.split(',') : [];
if (!optionsFromCommandline['i18n-locale']) {
if (!optionsFromCommandline.i18nLocale) {
if (languagesFromCommandline.length > 0) {
options['i18n-locale'] = languagesFromCommandline[0];
options.i18nLocale = languagesFromCommandline[0];
} else {
options['i18n-locale'] = defaultI18nLocale;
options.i18nLocale = defaultI18nLocale;
}
}
options.parsedLanguages = [options['i18n-locale']];
options.parsedLanguages = [options.i18nLocale];
if (optionsFromCommandline.languages) {
options.parsedLanguages.push(...languagesFromCommandline);
}
Expand All @@ -90,17 +90,17 @@ export function ngAdd(optionsFromCommandline: NgAddOptions): Rule {
template({
...stringUtils,
...(options as object),
'i18nLocale': options['i18n-locale'],
'i18nFormat': options['i18n-format']
'i18nLocale': options.i18nLocale,
'i18nFormat': options.i18nFormat
} as any),
move(options.path ? options.path : ''),
]);

const configurationAdditions = options.parsedLanguages
.filter(lang => lang !== options['i18n-locale'])
.filter(lang => lang !== options.i18nLocale)
.map(lang => addLanguageConfigurationToProject(options, lang));
const startScriptAdditions = options.parsedLanguages
.filter(lang => lang !== options['i18n-locale'])
.filter(lang => lang !== options.i18nLocale)
.map(lang => addStartScriptToPackageJson(options, lang));
return chain([
branchAndMerge(
Expand Down
12 changes: 6 additions & 6 deletions projects/tooling/src/schematics/src/ng-add/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describe('ng-add', () => {

it('should throw an exception when called with invalid language code as default language', () => {
try {
runSchematic({'i18n-locale': 'a,b'}, appTree);
runSchematic({i18nLocale: 'a,b'}, appTree);
fail('expected exception (is not a valid language code) did not occur');
} catch (e) {
expect(e.message).toContain('is not a valid language code');
Expand Down Expand Up @@ -105,7 +105,7 @@ describe('ng-add', () => {
});

it('should create xliffmerge configuration file containing all given languages and default language', () => {
const tree = runSchematic({'i18n-locale': 'en', languages: 'de,fr,ru'}, appTree);
const tree = runSchematic({i18nLocale: 'en', languages: 'de,fr,ru'}, appTree);
expect(tree.files).toContain('/projects/bar/xliffmerge.json');
const configFile = readAsJson<{xliffmergeOptions: IXliffMergeOptions}>(tree, '/projects/bar/xliffmerge.json');
expect(configFile.xliffmergeOptions).toBeTruthy();
Expand All @@ -115,7 +115,7 @@ describe('ng-add', () => {
});

it('should create xliffmerge configuration with specified xlf format', () => {
const tree = runSchematic({'i18n-locale': 'en', 'i18n-format': 'xlf2'}, appTree);
const tree = runSchematic({i18nLocale: 'en', i18nFormat: 'xlf2'}, appTree);
expect(tree.files).toContain('/projects/bar/xliffmerge.json');
const configFile = readAsJson<{xliffmergeOptions: IXliffMergeOptions}>(tree, '/projects/bar/xliffmerge.json');
expect(configFile.xliffmergeOptions).toBeTruthy();
Expand Down Expand Up @@ -171,7 +171,7 @@ describe('ng-add', () => {

it('should add npm script "start-xyz" to package.json when called with language xyz', () => {
const lang = 'xyz';
const tree = runSchematic({'i18n-locale': 'de', languages: lang}, appTree);
const tree = runSchematic({i18nLocale: 'de', languages: lang}, appTree);
const packageJson = readPackageJson(tree);
const startScriptDefaultLang = packageJson.scripts['start-de'];
expect(startScriptDefaultLang).toBeFalsy(); // no start script for default lang needed
Expand All @@ -186,7 +186,7 @@ describe('ng-add', () => {
// normally, when you specify a project "bar", start script should be called start-bar-xyz
// but if bar is the default project, it is just called start-xyz.
const lang = 'xyz';
const tree = runSchematic({'i18n-locale': 'de', project: 'bar', languages: lang}, appTree);
const tree = runSchematic({i18nLocale: 'de', project: 'bar', languages: lang}, appTree);
const packageJson = readPackageJson(tree);
const startScriptDefaultLang = packageJson.scripts['start-de'];
expect(startScriptDefaultLang).toBeFalsy(); // no start script for default lang needed
Expand Down Expand Up @@ -249,7 +249,7 @@ describe('ng-add', () => {
it('should add npm script "start-foolib-xyz" to package.json when called with language xyz', () => {
// when you specify a project "foo", start script should be called start-foo-xyz
const lang = 'xyz';
const tree = runSchematic({'i18n-locale': 'de', project: 'foo', languages: lang}, appTree);
const tree = runSchematic({i18nLocale: 'de', project: 'foo', languages: lang}, appTree);
const packageJson = readPackageJson(tree);
const startScriptDefaultLang = packageJson.scripts['start-de'];
expect(startScriptDefaultLang).toBeFalsy(); // no start script for default lang needed
Expand Down
9 changes: 5 additions & 4 deletions projects/tooling/src/schematics/src/ng-add/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,17 @@
"description": "The (optional) path where to create the translation files (relativ to src), default 'i18n'.",
"default": "i18n"
},
"i18n-format": {
"i18nFormat": {
"description": "The translation file format, 'xlf' for XLIFF 1.2, 'xlf2' for XLIFF 2 or 'xmb' for XMB/XTB.",
"enum": [
"xlf",
"xlf2",
"xmb"
],
"default": "xlf",
"description": "The translation file format, 'xlf' for XLIFF 1.2, 'xlf2' for XLIFF 2 or 'xmb' for XMB/XTB."
"type": "string",
"default": "xlf"
},
"i18n-locale": {
"i18nLocale": {
"type": "string",
"description": "The default language used in your ng template files (local name like 'en' or 'de'). If not given, first language in list of languages is assumed, if even that is not given, 'en' is assumed"
},
Expand Down
4 changes: 2 additions & 2 deletions projects/tooling/src/schematics/src/ng-add/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {CommonOptions} from '../common';

export interface NgAddOptions extends CommonOptions {
localePath?: string;
'i18n-format'?: string; // the used format
'i18n-locale'?: string; // the default language
i18nFormat?: string; // the used format
i18nLocale?: string; // the default language
languages?: string; // comma separared list of languages
useComandlineForLanguages?: boolean; // if set, all languages are given as command line argument to xliffmerge
// if not, they are configured in xliffmerge.json (preferred variant)
Expand Down
Loading

0 comments on commit 8a2b5a8

Please sign in to comment.