xlf-translate-auto 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,50 @@
1
+ # This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
2
+ # For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages
3
+
4
+ name: Publish NPM Package
5
+
6
+ on:
7
+ release:
8
+ types: [created]
9
+ # Allows you to run this workflow manually from the Actions tab
10
+ workflow_dispatch:
11
+
12
+ jobs:
13
+ build:
14
+ runs-on: ubuntu-latest
15
+ steps:
16
+ - uses: actions/checkout@v2
17
+ - uses: actions/setup-node@v2
18
+ with:
19
+ node-version: 12
20
+ - run: npm ci
21
+ - run: npm test
22
+
23
+ publish-npm:
24
+ needs: build
25
+ runs-on: ubuntu-latest
26
+ steps:
27
+ - uses: actions/checkout@v2
28
+ - uses: actions/setup-node@v2
29
+ with:
30
+ node-version: '12.x'
31
+ registry-url: 'https://registry.npmjs.org'
32
+ - run: npm install
33
+ - run: npm version
34
+ - run: npm publish
35
+ env:
36
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
37
+
38
+ # publish-gpr:
39
+ # needs: build
40
+ # runs-on: ubuntu-latest
41
+ # steps:
42
+ # - uses: actions/checkout@v2
43
+ # - uses: actions/setup-node@v1
44
+ # with:
45
+ # node-version: 12
46
+ # registry-url: https://npm.pkg.github.com/
47
+ # - run: npm ci
48
+ # - run: npm publish
49
+ # env:
50
+ # NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
@@ -0,0 +1,20 @@
1
+ name: Test On Push
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - master
7
+ pull_request:
8
+ branches:
9
+ - master
10
+
11
+ jobs:
12
+ test:
13
+ runs-on: ubuntu-latest
14
+ steps:
15
+ - uses: actions/checkout@v2
16
+ - uses: actions/setup-node@v1
17
+ with:
18
+ node-version: 12
19
+ - run: npm ci
20
+ - run: npm test
@@ -0,0 +1,4 @@
1
+ {
2
+ "singleQuote": true,
3
+ "tabWidth": 4
4
+ }
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 Nathan Friend
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,119 @@
1
+ # xlf-translate-auto (ex. xlf2xlf)
2
+
3
+ A command-line utility to automatically translate .xlf translation files v1.2 or v2 using Google Translate
4
+
5
+ **DISCLAIMER**
6
+
7
+ > This library was forked from https://github.com/nfriend/xlf-translate-auto
8
+
9
+ > Some additions to package dependecies were made according to https://www.npmjs.com/package/xlf-translate-auto-updated
10
+
11
+ The main goal to fork and edit original tool was to preserve word and interpolation blocks order while translating original _.xlf_ file, as base library copied this interpolation blocks to the end of _target_ element.
12
+
13
+ While making this improvements, the original _translate.js_ file eas fully rewritten starting from library we are using to read and build object model of _.xlf_ to ending with how we are parsing object model tree itself and creating queue to translate.
14
+
15
+ Also most of redundant dependecies were removed, file and folder structure were redefined.
16
+
17
+ ## Installation
18
+
19
+ This is a command-line utility. To install this utility, run:
20
+
21
+ ```bash
22
+ npm install -g xlf-translate-auto
23
+ ```
24
+
25
+ This will install the utility globally so that it can be run from any location. The executable installed by this module is `xlf-translate-auto`.
26
+ ___
27
+
28
+ You also could run library using **npx** utility.
29
+
30
+
31
+ ```bash
32
+ npx xlf-translate-auto [options]
33
+ ```
34
+
35
+ ## Usage
36
+
37
+ Before you begin, you will need an `.xlf` file to translate!
38
+
39
+ If you are using [Angular 2+](https://angular.io/) and the [Angular CLI](https://cli.angular.io/), you will probably extract an `.xlf` file from your app by [running `ng xi18n` inside your Angular project](https://angular.io/guide/i18n#create-a-translation-source-file-with-ng-xi18n). This produces a file named `messages.xlf` inside your project folder.
40
+
41
+ Say we have an `.xlf` file named `messages.xlf`. Let's translate this file from English ("en") to Hindi ("hi") and save the translated file as `messages.hi.xlf`:
42
+
43
+ ```bash
44
+ xlf-translate-auto --in messages.xlf --out messages.hi.xlf --from en --to hi
45
+ ```
46
+
47
+ Or, if you don't like typing too much, you can use the abbreviated versions of the arguments:
48
+
49
+ ```bash
50
+ xlf-translate-auto -i messages.xlf -o messages.hi.xlf -f en -t nl
51
+ ```
52
+
53
+ For more usage help, run:
54
+
55
+ ```bash
56
+ xlf-translate-auto help
57
+ ```
58
+
59
+ > If the utility not installed globally, just use it via npx, e.g. `npx xlf-translate-auto --in messages.xlf --out messages.hi.xlf --from en --to hi`
60
+
61
+ ## Messages
62
+
63
+ Tool adds 2 kind of extra messages to final xlf file according to certain criterias:
64
+
65
+ 1. If we are using `skip` option, there will be information messages inside target tags to ease spot of where translation should be placed.
66
+
67
+ Message:
68
+ ```
69
+ [INFO] Add your translation here
70
+ ```
71
+
72
+ 2. If there is any errors during quering the translation, there will be warning messages inside problematic target tags to ease spot where things went wrong.
73
+
74
+ Message:
75
+ ```
76
+ [WARN] Failed to translate
77
+ ```
78
+
79
+ ## Parameters
80
+
81
+ | Option | Default | Mandatory | Description |
82
+ |-----------------|-----------|-------------|-----------------------------------|
83
+ | i / in | - | true | The input .xlf file to translate |
84
+ | o / out | - | true | The name of the translated output file |
85
+ | f / from | - | true | The language code of the input file |
86
+ | t / to | - | true | The language code to translate to |
87
+ | r / rate | 500 | false | How long to wait after launching a job before launching another one in ms. For more information see [https://github.com/SGrondin/bottleneck#docs](https://github.com/SGrondin/bottleneck) |
88
+ | c / concurrent | 4 | false | How many jobs can be executing at the same time. For more information see [https://github.com/SGrondin/bottleneck#docs](https://github.com/SGrondin/bottleneck) |
89
+ | s / skip | false | false | Skips translating and adds only target tag with boilerplate text `[INFO] Add your translation here` |
90
+ | p / proxy | false | false | Use custom proxy |
91
+ | ap / autoProxy | - | false | Use default proxy |
92
+ | cs / clearState | false | false | Clear state once translated |
93
+
94
+
95
+ ## 🤒 Known issues
96
+
97
+ - The speed of quering / getting response is depends on network quality.
98
+
99
+ - Sometimes translation could end up with tons of errors like `{"name":"HTTPError","statusCode":429,"statusMessage":"Too Many Requests"}`, in this case better to wait for some time before next iteration.
100
+
101
+ In case you are starting to get `{"name":"HTTPError","statusCode":429,"statusMessage":"Too Many Requests"}` you could do the following:
102
+
103
+ - Wait a bit before Google Translate will stop blocking your IP
104
+ - Try to set bigger rate `npx xlf-translate-auto --in messages.xlf --out messages.hi.xlf --from en --to hi --rate 5000`, where rate is ms between queries. For more information on that property see [https://github.com/SGrondin/bottleneck](https://github.com/SGrondin/bottleneck#docs)
105
+ - Try to limit rate and amount of concurrent requests `npx xlf-translate-auto --in messages.xlf --out messages.hi.xlf --from en --to hi --rate 10000 --concurrent 1`
106
+
107
+ ## Developing
108
+
109
+ The easiest way to develop on this module is to use test-driven development.
110
+
111
+ Unit tests can be run with `npm test`. To automatically re-run the tests when you make changes to the files, run `npm run test:watch`.
112
+
113
+ ## Translation
114
+
115
+ This utility uses Google Translate's online API for its translations using this NPM package: https://www.npmjs.com/package/@k3rn31p4nic/google-translate-api
116
+
117
+ ## XLIF 1.2 Specification
118
+
119
+ [http://docs.oasis-open.org/xliff/v1.2/os/xliff-core.html](http://docs.oasis-open.org/xliff/v1.2/os/xliff-core.html)