Skip to content

Commit

Permalink
added XLIFF 2.0 support
Browse files Browse the repository at this point in the history
  • Loading branch information
martinroob committed May 5, 2017
1 parent 6e453e7 commit 0ae8df5
Show file tree
Hide file tree
Showing 11 changed files with 1,075 additions and 15 deletions.
9 changes: 8 additions & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
<a name="0.4-0"></a>
<a name="0.5.0"></a>
# [0.5.0](https://github.com/martinroob/ngx-i18nsupport/compare/v0.4.0...v0.5.0) (2017-05-05)

### Features

* **xliffmerge:** added XLIFF 2.0 support. ([#20](https://github.com/martinroob/ngx-i18nsupport/issues/20))

<a name="0.4.0"></a>
# [0.4.0](https://github.com/martinroob/ngx-i18nsupport/compare/v0.3.1...v0.4.0) (2017-05-03)

### Bug Fixes
Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ It is described in the official documentation Angular Cookbook [Internationaliza

Said in one sentence,
* markup your strings to translate in your templates with an attribute `i18n`
* run the Amgular extraction tool (`ng-xi18n`) to extract the strings in an XML Format called [[XLIFF]]((http://docs.oasis-open.org/xliff/xliff-core/xliff-core.html))
* run the Amgular extraction tool (`ng-xi18n`) to extract the strings in an XML Format called [[XLIFF-1.2]](http://docs.oasis-open.org/xliff/v1.2/os/xliff-core.html)
* copy and then translate the extracted file for every language you plan to support
* run the ng compiler to generate a special version of your app for the different languages

Expand Down Expand Up @@ -104,8 +104,8 @@ The options are:
- `srcDir` (string, default "."): directory, where the master file is expected
- `genDir` (string, default "."): directory, where files are written to (normally identical with srcDir)
- `i18nFile` (string, default "messages.xlf"): master file (relativ to srcDir)
- `i18nFormat` (string, default "xlf"): "xlf" for XLIFF or "xmb" for XML Message Bundles
- `encoding` (string, default "UTF-8"): expected encoding of xlf or xmb files
- `i18nFormat` (string, default "xlf"): `xlf` for XLIFF 1.2 or `xlf2` for XLIFF 2.0 or `xmb` for XML Message Bundles
- `encoding` (string, default "UTF-8"): expected encoding of xlf, xlf2 or xmb files
- `defaultLanguage` (string, default "en"): the native language used in your templates
- `languages` (array of strings): list of languages (if not spefified at command line)
- `removeUnusedIds` (boolean, default `true`): flag, if unused IDs should be removed during merge
Expand Down Expand Up @@ -201,7 +201,8 @@ But if you are interesting, send me an email, so that we can discuss it.
* Phillippe Martin
[Deploying an i18n Angular app with angular-cli](https://medium.com/@feloy/deploying-an-i18n-angular-app-with-angular-cli-fc788f17e358)
* Roland Oldengarm: [Angular 2: Automated i18n workflow using gulp](http://rolandoldengarm.com/index.php/2016/10/17/angular-2-automated-i18n-workflow-using-gulp/)
* XLIFF Specification: [XLIFF Spec](http://docs.oasis-open.org/xliff/xliff-core/xliff-core.html)
* XLIFF 1.2 Specification: [XLIFF-1.2](http://docs.oasis-open.org/xliff/v1.2/os/xliff-core.html)
* XLIFF 2.0 Specification: [XLIFF-2.0](http://docs.oasis-open.org/xliff/xliff-core/v2.0/os/xliff-core-v2.0-os.html)
* My Tiny Translator Tool: [TinyTranslator](https://github.com/martinroob/tiny-translator)

[travis-badge]: https://travis-ci.org/martinroob/ngx-i18nsupport.svg?branch=master
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@
"dependencies": {
"chalk": "^1.1.3",
"commander": "^2.9.0",
"ngx-i18nsupport-lib": "^0.0.8"
"ngx-i18nsupport-lib": "^0.1.3"
}
}
8 changes: 4 additions & 4 deletions src/xliffmerge/xliff-merge-parameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,9 @@ export class XliffMergeParameters {
} catch (err) {
this.errorsFound.push(new XliffMergeError('i18nFile "' + this.i18nFile() + '" is not readable'));
}
// i18nFormat must be xlf or xmb
if (!(this.i18nFormat() === 'xlf' || this.i18nFormat() === 'xmb')) {
this.errorsFound.push(new XliffMergeError('i18nFormat "' + this.i18nFormat() + '" invalid, must be "xlf" or "xmb"'));
// i18nFormat must be xlf xlf2 or xmb
if (!(this.i18nFormat() === 'xlf' || this.i18nFormat() === 'xlf2' || this.i18nFormat() === 'xmb')) {
this.errorsFound.push(new XliffMergeError('i18nFormat "' + this.i18nFormat() + '" invalid, must be "xlf" or "xlf2" or "xmb"'));
}
}

Expand Down Expand Up @@ -267,7 +267,7 @@ export class XliffMergeParameters {

/**
* Format of the master xlif file.
* Default is "xlf", possible are "xlf" or "xmb".
* Default is "xlf", possible are "xlf" or "xlf2" or "xmb".
* @return {string}
*/
public i18nFormat(): string {
Expand Down
387 changes: 387 additions & 0 deletions src/xliffmerge/xliff-merge.spec.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/xliffmerge/xliff-merge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export class XliffMerge {
/**
* The read master xlf file.
*/
private master: ITranslationMessagesFile; // XliffFile or XmbFile
private master: ITranslationMessagesFile; // XliffFile or Xliff2File or XmbFile

/**
* For Tests, create instance with given profile
Expand Down
216 changes: 216 additions & 0 deletions test/testdata/i18n/ngExtractedMaster1.xlf2
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
<?xml version="1.0" encoding="UTF-8" ?>
<xliff version="2.0" xmlns="urn:oasis:names:tc:xliff:document:2.0" srcLang="en">
<file original="ng.template" id="ngi18n">
<unit id="2047558209369508311">
<segment>
<source>Meine erste I18N-Anwendung</source>
</segment>
</unit>
<unit id="4371668001355139802">
<segment>
<source>Anwendung läuft!</source>
</segment>
</unit>
<unit id="7499557905529977371">
<notes>
<note category="description">Beschreibung der Anwendung</note>
</notes>
<segment>
<source>Diese Anwendung ist eine reine Demonstration und hat keine wirklich nutzbare Funktion.</source>
</segment>
</unit>
<unit id="3274258156935474372">
<notes>
<note category="description">sampleapp.appdescription</note>
<note category="meaning">ngx-translate</note>
</notes>
<segment>
<source>Diese Anwendung ist eine reine Demonstration und hat keine wirklich nutzbare Funktion.</source>
</segment>
</unit>
<unit id="9030312858648510700">
<notes>
<note category="description">placeholder sample</note>
</notes>
<segment>
<source>Eintrag <ph id="0" equiv="INTERPOLATION" disp="{{number()}}"/> von <ph id="1" equiv="INTERPOLATION_1" disp="{{total()}}"/> hinzugefügt.</source>
</segment>
</unit>
<unit id="7149517499881679376">
<notes>
<note category="description">linebreak sample</note>
</notes>
<segment>
<source>Dieser Text
enthält einen Zeilenumbruch.</source>
</segment>
</unit>
<unit id="8998006760999956868">
<notes>
<note category="description">embedded html sample</note>
</notes>
<segment>
<source>Dieser Text enthält <pc id="0" equivStart="START_BOLD_TEXT" equivEnd="CLOSE_BOLD_TEXT" type="fmt" dispStart="&lt;b&gt;" dispEnd="&lt;/b&gt;">eingebettetes html</pc></source>
</segment>
</unit>
<unit id="5917488050182782344">
<segment>
<source>Eine Nachricht per ngx-translate</source>
</segment>
</unit>
<unit id="6797180050921917715">
<notes>
<note category="description">ngx-translate</note>
<note category="meaning">appTitle</note>
</notes>
<segment>
<source>Sample App Title</source>
</segment>
</unit>
<unit id="8247252724313224625">
<notes>
<note category="description">ngx-translate</note>
<note category="meaning">messages.example</note>
</notes>
<segment>
<source><ph id="0" equiv="INTERPOLATION" disp="{{priority}}"/>: A message from a service</source>
</segment>
</unit>
<unit id="1650190705028986163">
<notes>
<note category="description">ngx-translate</note>
<note category="meaning">myapp</note>
</notes>
<segment>
<source>Meine Anwendung</source>
</segment>
</unit>
<unit id="6830980354990918030">
<notes>
<note category="description">ngx-translate</note>
<note category="meaning">dateservice.monday</note>
</notes>
<segment>
<source>Montag</source>
</segment>
</unit>
<unit id="6375749062310329756">
<notes>
<note category="description">ngx-translate</note>
<note category="meaning">dateservice.tuesday</note>
</notes>
<segment>
<source>Dienstag</source>
</segment>
</unit>
<unit id="8721860357562818797">
<notes>
<note category="description">ngx-translate</note>
<note category="meaning">dateservice.wednesday</note>
</notes>
<segment>
<source>Mittwoch</source>
</segment>
</unit>
<unit id="1711956122115192435">
<notes>
<note category="description">ngx-translate</note>
<note category="meaning">dateservice.thursday</note>
</notes>
<segment>
<source>Donnerstag</source>
</segment>
</unit>
<unit id="6553664200740484336">
<notes>
<note category="description">ngx-translate</note>
<note category="meaning">dateservice.friday</note>
</notes>
<segment>
<source>Freitag</source>
</segment>
</unit>
<unit id="3334880142338745041">
<notes>
<note category="description">ngx-translate</note>
<note category="meaning">dateservice.saturday</note>
</notes>
<segment>
<source>Samstag</source>
</segment>
</unit>
<unit id="1409816038285774052">
<notes>
<note category="description">ngx-translate</note>
<note category="meaning">dateservice.sunday</note>
</notes>
<segment>
<source>Sonntag</source>
</segment>
</unit>
<unit id="7644074577681906834">
<notes>
<note category="description">ngx-translate</note>
<note category="meaning">placeholders.test1placeholder</note>
</notes>
<segment>
<source><ph id="0" equiv="INTERPOLATION" disp="{{priority}}"/>: Eine Nachricht mit einem Platzhalter</source>
</segment>
</unit>
<unit id="9223042936546558865">
<notes>
<note category="description">ngx-translate</note>
<note category="meaning">placeholders.test2placeholder</note>
</notes>
<segment>
<source><ph id="0" equiv="INTERPOLATION" disp="{{priority}}"/>: Eine Nachricht mit 2 Platzhaltern: <ph id="1" equiv="INTERPOLATION_1" disp="{{placeholder2}}"/></source>
</segment>
</unit>
<unit id="7049669989298349710">
<notes>
<note category="description">ngx-translate</note>
<note category="meaning">placeholders.test2placeholderRepeated</note>
</notes>
<segment>
<source><ph id="0" equiv="INTERPOLATION" disp="{{priority}}"/>: Eine Nachricht mit 2 Platzhaltern: <ph id="1" equiv="INTERPOLATION" disp="{{priority}}"/> <ph id="2" equiv="INTERPOLATION_1" disp="{{placeholder2}}"/></source>
</segment>
</unit>
<unit id="6651165993266138235">
<notes>
<note category="description">ngx-translate</note>
<note category="meaning">embeddedhtml.bold</note>
</notes>
<segment>
<source>Diese Nachricht ist <pc id="0" equivStart="START_BOLD_TEXT" equivEnd="CLOSE_BOLD_TEXT" type="fmt" dispStart="&lt;b&gt;" dispEnd="&lt;/b&gt;">WICHTIG</pc></source>
</segment>
</unit>
<unit id="7609655310648429098">
<notes>
<note category="description">ngx-translate</note>
<note category="meaning">embeddedhtml.boldstrong</note>
</notes>
<segment>
<source>Diese Nachricht ist <pc id="0" equivStart="START_BOLD_TEXT" equivEnd="CLOSE_BOLD_TEXT" type="fmt" dispStart="&lt;b&gt;" dispEnd="&lt;/b&gt;"><pc id="1" equivStart="START_TAG_STRONG" equivEnd="CLOSE_TAG_STRONG" type="other" dispStart="&lt;strong&gt;" dispEnd="&lt;/strong&gt;">SEHR WICHTIG</pc></pc></source>
</segment>
</unit>
<unit id="7610784844464920497">
<notes>
<note category="description">ngx-translate</note>
<note category="meaning">embeddedhtml.strange</note>
</notes>
<segment>
<source>Diese Nachricht ist <pc id="0" equivStart="START_TAG_STRANGE" equivEnd="CLOSE_TAG_STRANGE" type="other" dispStart="&lt;strange&gt;" dispEnd="&lt;/strange&gt;"><ph id="1" equiv="INTERPOLATION" disp="{{strangeness}}"/></pc></source>
</segment>
</unit>
<unit id="explicitlysetids.test1">
<segment>
<source>Explizit gesetzte ID</source>
</segment>
</unit>
<unit>
<segment>
<source>unit without id</source>
</segment>
</unit>
</file>
</xliff>
Loading

0 comments on commit 0ae8df5

Please sign in to comment.