Skip to content

Commit

Permalink
Applanga Command Line Interface Version 1.0.92
Browse files Browse the repository at this point in the history
  • Loading branch information
steffen authored and steffen committed Jan 4, 2024
1 parent d8e96c3 commit 84b0cc3
Show file tree
Hide file tree
Showing 5 changed files with 151 additions and 6 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,16 @@
*Applanga CLI Documentation:* <https://www.applanga.com/docs-integration/cli>
***

### Version 1.0.92 (4 Jan 2024)
#### Added
- Added `xliff` file format
- Added `X-Integration` header
---

### Version 1.0.91 (7 Dec 2023)
#### Added
- Added `remove_cr_char` option
---

### Version 1.0.89 (7 Aug 2023)
#### Added
Expand Down
70 changes: 67 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Applanga Localization Command Line Interface (CLI)

***
*Version:* 1.0.91
*Version:* 1.0.92

*Website:* <https://www.applanga.com>

Expand Down Expand Up @@ -98,7 +98,7 @@ To push existing local translations to Applanga:
applanga push
```

The default config usually just pushes the source language and pulls all target languages. For some initial setup cases, you may need to push target values as well. For this case, there is the **pushtarget** command. It behaves the same as the push command, but this command pushes all files that are set as targets in the config. If you want to override already existing translations on the backend, you’ll need to combine this with the `--force` command
The default config usually just pushes the source language and pulls all target languages. For some initial setup cases, you may need to push target values as well. For this case, there is the **pushtarget** command. It behaves the same as the push command, but this command pushes all files that are set as targets in the config. If you want to override already existing translations on the backend, you’ll need to combine this with the `--force` command. Exception for this is the `xliff` file format. For this format `--force` is disabled. If you want to override existing values/translations please provide the `onlyIfTextEmpty` option and set it to `false`

```sh
applanga pushtarget
Expand All @@ -116,7 +116,9 @@ For cases where you need to pull the source language changes from the dashboard

- **--force**

By default values are only pushed if they do not yet exist on the dashboard. This prevents accidental overwrite of translations. If you want to push locally changed files you can do so with the `--force` option. But be cautious with this option as it might overwrite values set by a translator on the dashboard; be sure to pull before you push.
By default values are only pushed if they do not yet exist on the dashboard. This prevents accidental overwrite of translations. If you want to push locally changed files you can do so with the `--force` option. But be cautious with this option as it might overwrite values set by a translator on the dashboard; be sure to pull before you push.

For the xliff file format, the only way to override existing values or translations is by providing the onlyIfTextEmpty option and setting it to false. It's important to note that the --force option should not be used in conjunction with the xliff file format and the onlyIfTextEmpty option set to false, as the --force option is disregarded in this context.

```sh
applanga push --force
Expand Down Expand Up @@ -215,6 +217,7 @@ There are a few mandatory and several optional properties that you can use to cu
- microsoft_resw: [Microsoft Resw](https://www.applanga.com/docs/formats/microsoft_resx) (.resw)
- microsoft_resx: [Microsoft Resx](https://www.applanga.com/docs/formats/microsoft_resx) (.resx)
- toml : [Toml](https://www.applanga.com/docs/formats/toml) (.toml)
- xliff: [Xliff](https://www.applanga.com/docs/formats/xliff) (.xliff)

***Example:*** `"file_format": "android_xml"`

Expand Down Expand Up @@ -410,7 +413,68 @@ It is possible to set the variable `<language>` in the path. In the "source" blo
In download when the option set to `true`, the downloded files will contain only the Unicode/Mac new line character (LF).

***Example:*** `"remove_cr_char": true`


### Xliff specific options

The following options will only work if the file_format is set to `xliff` (see [Applanga Xliff Format Documentation](https://applanga.com/docs/formats/xliff) for more information of the xliff format).


- **"xliffStatus"**

The files will import/export the given statuses of the xliff file. This options by default is set to `false`.

***Example:*** `"xliffStatus": true`

- **"createUnknownCustomStates"** *(push commands only)*

Default value is `false`. If set to true custom statuses provided inside the xliff format will be importet into Applanga.

***Example:*** `"createUnknownCustomStates": true`

- **"includeContextUrl"** *(pull commands only)*

The downloaded xliff file will include contextUrl's for screenshots of the project

***Example:*** `"includeContextUrl": true`

- **"importSourceLanguage"** *(push commands only)*

If the source language varies from the base language of the project you can specify this parameter to have a correct import adjusting for the varying base language. Default is `false`. To upload with a specified source language set this to the language iso name of the language.

***Example:*** `"importSourceLanguage": "en"`

- **"skipLockedTranslations"** *(push commands only)*

Default is `false`. If set to true all entries inside the uploaded file, that are locked in your application, will be ignored.

***Example:*** `"skipLockedTranslations": true`

- **"skipEmptyTranslations"** *(push commands only)*

Default is `false`. By default entries inside the file that are empty will be ignored in the `xliff` format. If this option is true, empty entries inside the file will be created in the Project. Empty entries will never overwrite entries that already exist within the Project.


***Example:*** `"skipEmptyTranslations": true`

- **"onlyAsDraft"** *(push commands only)*

Default is `false`. If set to true all values inside the xliff will only be applied to draft values of the application. If your application is a Branching application, this value will be ignored.

***Example:*** `"onlyAsDraft": true`

- **"onlyIfTextEmpty"** *(push commands only)*

The pushed file will only overwrite keys that do have an empty text value in Applanga. This overrides the --force option of the commandline. Default is set to `true`.

***Example:*** `"onlyIfTextEmpty": true`

- **"importIntoGroup"** *(push commands only)*

Default is `false`. By default all Keys will be pushed into the groups they currently are assigned to. If true all pushed keys in the file will be but into the 'main' group.

***Example:*** `"importIntoGroup": true`

# Configuration Examples
---
## Android Configuration Examples
Expand Down
55 changes: 53 additions & 2 deletions lib/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ def downloadFile(file_data, debug=False):
if 'includeInvisibleId' in file_data:
request_options['includeInvisibleId'] = file_data['includeInvisibleId']

if 'xliffStatus' in file_data:
request_options['xliffStatus'] = file_data['xliffStatus']

if 'includeContextUrl' in file_data:
request_options['includeContextUrl'] = file_data['includeContextUrl']

# check conditions for key_prefix
if 'key_prefix' in file_data:
if len(file_data['key_prefix']) > 50:
Expand Down Expand Up @@ -246,9 +252,30 @@ def uploadFiles(upload_files, force=False, draft=False, debug=False):
if 'disable_plurals' in file_data:
send_data['disable_plurals'] = file_data['disable_plurals']

if 'xliffStatus' in file_data:
send_data['xliffStatus'] = file_data['xliffStatus']

if file_data['file_format'] in ['xliff'] and 'skipLockedTranslations' in file_data:
send_data['skipLockedTranslations'] = file_data['skipLockedTranslations']

if file_data['file_format'] in ['xliff'] and 'skipEmptyTranslations' in file_data:
send_data['skipEmptyTranslations'] = file_data['skipEmptyTranslations']

if file_data['file_format'] in ['xliff'] and 'createUnknownCustomStates' in file_data:
send_data['createUnknownCustomStates'] = file_data['createUnknownCustomStates']

if 'remove_cr_char' in file_data:
send_data['removeCrChar'] = file_data['remove_cr_char']

if 'onlyIfTextEmpty' in file_data and file_data['file_format'] in ['xliff']:
send_data['onlyIfTextEmpty'] = file_data['onlyIfTextEmpty']

if file_data['file_format'] in ['xliff'] and'onlyAsDraft' in file_data:
send_data['onlyAsDraft'] = file_data['onlyAsDraft']

if file_data['file_format'] in ['xliff'] and 'importSourceLanguage' in file_data:
send_data['importSourceLanguage'] = file_data['importSourceLanguage']

response = uploadFile(send_data, force=force, draft=draft, debug=debug)
return_data.append(
{
Expand Down Expand Up @@ -286,12 +313,35 @@ def uploadFile(file_data, force=False, draft=False, debug=False):
# Request the file from server
request_options = {
'onlyIfTextEmpty': not force,
'onlyAsDraft': draft
'onlyAsDraft': draft,
}

if file_data['file_format'] in ['nested_json', 'react_nested_json'] and 'disable_plurals' in file_data:
request_options['disablePlurals'] = file_data['disable_plurals'] is True

if file_data['file_format'] in ['xliff'] and 'importSourceLanguage' in file_data:
request_options['importSourceLanguage'] = file_data['importSourceLanguage']

if file_data['file_format'] in ['xliff'] and 'xliffStatus' in file_data:
request_options['xliffStatus'] = file_data['xliffStatus']

if file_data['file_format'] in ['xliff'] and 'createUnknownCustomStates' in file_data:
request_options['createUnknownCustomStates'] = file_data['createUnknownCustomStates']

if 'skipLockedTranslations' in file_data and file_data['file_format'] in ['xliff']:
request_options['skipLockedTranslations'] = file_data['skipLockedTranslations']

if file_data['file_format'] in ['xliff'] and 'skipEmptyTranslations' in file_data:
request_options['skipEmptyTranslations'] = file_data['skipEmptyTranslations']

if file_data['file_format'] in ['xliff'] and 'onlyIfTextEmpty' in file_data:
request_options['onlyIfTextEmpty'] = file_data['onlyIfTextEmpty']
elif file_data['file_format'] in ['xliff']:
request_options['onlyIfTextEmpty'] = True

if file_data['file_format'] in ['xliff'] and'onlyAsDraft' in file_data:
request_options['onlyAsDraft'] = file_data['onlyAsDraft']

if 'removeCrChar' in file_data:
request_options['removeCrChar'] = file_data['removeCrChar']

Expand Down Expand Up @@ -407,7 +457,8 @@ def makeRequest(data={}, api_path=None, access_token=None, upload_file=None, met

headers = {
'Authorization': 'Bearer ' + access_token,
'CLI-Version': constants.VERSION_NUMBER
'CLI-Version': constants.VERSION_NUMBER,
'X-Integration': constants.X_INTEGRATION_HEADER_VALUE
}

url = constants.APPLANGA_HOST
Expand Down
9 changes: 8 additions & 1 deletion lib/constants.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
VERSION_NUMBER = '1.0.91'
VERSION_NUMBER = '1.0.92'
APPLANGA_HOST = 'https://api.applanga.com'
API_BASE_PATH = '/v1/api'
CONFIG_FILE_NAME = '.applanga.json'
DEBUG_TEXT_COLOR = 'blue'
ENVIRONMENT_VARIABLE = 'APPLANGA_CONFIG'
X_INTEGRATION_HEADER_VALUE = '1'
FILE_FORMATS = {
'android_xml': {
'name': 'Android XML',
Expand Down Expand Up @@ -169,5 +170,11 @@
'extension': 'toml',
'default_file_path': './<language>.toml',
'default_tag_name': 'app:language.toml'
},
'xliff': {
'name': 'Xliff',
'extension': 'xliff',
'default_file_path': './<language>.xliff',
'default_tag_name': 'app:language.xliff'
}
}
16 changes: 16 additions & 0 deletions lib/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,22 @@ def getFiles(source):
if 'disable_plurals' in source:
return_files[file]['disable_plurals'] = source['disable_plurals']

if 'xliffStatus' in source:
return_files[file]['xliffStatus'] = source['xliffStatus']
if 'createUnknownCustomStates' in source:
return_files[file]['createUnknownCustomStates'] = source['createUnknownCustomStates']
if 'importSourceLanguage' in source:
return_files[file]['importSourceLanguage'] = source['importSourceLanguage']
if 'skipLockedTranslations' in source:
return_files[file]['skipLockedTranslations'] = source['skipLockedTranslations']
if 'skipEmptyTranslations' in source:
return_files[file]['skipEmptyTranslations'] = source['skipEmptyTranslations']
if 'onlyIfTextEmpty' in source:
return_files[file]['onlyIfTextEmpty'] = source['onlyIfTextEmpty']
if 'onlyAsDraft' in source:
return_files[file]['onlyAsDraft'] = source['onlyAsDraft']
if 'importIntoGroup' in source:
return_files[file]['importIntoGroup'] = source['importIntoGroup']

return {
'skipped': skipped_files,
Expand Down

0 comments on commit 84b0cc3

Please sign in to comment.