Skip to content

Commit

Permalink
Applanga Command Line Interface Version 1.0.76
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenkins authored and Jenkins committed Nov 29, 2022
1 parent 6a09338 commit 3c4afb2
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
*Applanga CLI Documentation:* <https://www.applanga.com/docs-integration/cli>
***

### Version 1.0.76 (29 Nov 2022)
#### Added
- Added `key_prefix` option

### Version 1.0.75 (13 Jun 2022)
#### Fixed
- Fixed documentation to include the new includeInvisibleId command option
Expand Down
16 changes: 13 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.75
*Version:* 1.0.76

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

Expand Down Expand Up @@ -53,13 +53,13 @@ To update to the latest version call:
```

###### Installing on Mac pre MacOSX 11
Please note that in order to run the latest Applanga CLI version on macOS you need to have at least macOS 11 (Big Sur) installed. If you are stuck with an older macOS you can use [Applanga CLI 1.0.75](https://github.com/applanga/applanga-cli/releases/tag/1.0.51) but be aware that not all features and fixes are available in that version. Please check the [Applanga CLI 1.0.51 README](https://github.com/applanga/applanga-cli/blob/1.0.51/README.md) and [CHANGELOG](https://www.applanga.com/changelog/cli) for more details.
Please note that in order to run the latest Applanga CLI version on macOS you need to have at least macOS 11 (Big Sur) installed. If you are stuck with an older macOS you can use [Applanga CLI 1.0.76](https://github.com/applanga/applanga-cli/releases/tag/1.0.51) but be aware that not all features and fixes are available in that version. Please check the [Applanga CLI 1.0.51 README](https://github.com/applanga/applanga-cli/blob/1.0.51/README.md) and [CHANGELOG](https://www.applanga.com/changelog/cli) for more details.

In order to install this via brew you need to run:

```sh
brew tap applanga/cli
brew install [email protected].75
brew install [email protected].76
```

##### Github
Expand Down Expand Up @@ -370,6 +370,16 @@ It is possible to set the variable `<language>` in the path. In the "source" blo
- All instances of "%s" will be converted to "%@".

- If it is the same pattern, will keep the original.

- **"key_prefix"**

If you need to import multiple files with similar keys but different text, the option allows to add prefixes to the keys on import and remove prefixes on export.

**Note**:

The `key_prefix` text property cannot be longer than 50 characters and can only contains letters, numbers, space, undescore and dash.

***Example:*** `"key_prefix": "added_prefix1-"`

# Configuration Examples
---
Expand Down
38 changes: 38 additions & 0 deletions lib/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import requests
import json
import os
import re
from lib import constants
from lib import config_file
from lib import files
Expand Down Expand Up @@ -60,7 +61,15 @@ def downloadFile(file_data, debug=False):
if 'includeInvisibleId' in file_data:
request_options['includeInvisibleId'] = file_data['includeInvisibleId']

# check conditions for key_prefix
if 'key_prefix' in file_data:
if len(file_data['key_prefix']) > 50:
raise ApplangaRequestException('The key prefix cannot be longer than 50 characters: %s\nFor more informations and examples on how todo that please refer to the Applanga CLI Integration Documentation.' % (file_data['key_prefix']))

pattern = re.compile('^[a-zA-Z0-9 _-]*$')
matchPatter = pattern.match(file_data['key_prefix'])
if not matchPatter:
raise ApplangaRequestException('The key prefix can contain only letters, numbers, space, undescore and dash: %s\nFor more informations and examples on how todo that please refer to the Applanga CLI Integration Documentation.' % (file_data['key_prefix']))

try:
# Request the file from server
Expand All @@ -71,6 +80,9 @@ def downloadFile(file_data, debug=False):
}
if 'tag' in file_data:
request_data['tag'] = file_data['tag']

if 'key_prefix' in file_data:
request_data['removeKeyPrefix'] = file_data['key_prefix']

response = makeRequest(data=request_data, api_path='/files', debug=debug)

Expand Down Expand Up @@ -163,6 +175,27 @@ def uploadFiles(upload_files, force=False, draft=False, debug=False):
)
continue

# check conditions for key_prefix
if 'path' in source and 'key_prefix' in source:
if len(source['key_prefix']) > 50:
return_data.append(
{
'path': source['key_prefix'],
'error': 'The key prefix cannot be longer than 50 characters. \nFor more informations and examples on how todo that please refer to the Applanga CLI Integration Documentation.'
}
)
continue
pattern = re.compile('^[a-zA-Z0-9 _-]*$')
matchPatter = pattern.match(source['key_prefix'])
if not matchPatter:
return_data.append(
{
'path': source['key_prefix'],
'error': 'The key prefix can contain only letters, numbers, space, undescore and dash. \nFor more informations and examples on how todo that please refer to the Applanga CLI Integration Documentation.'
}
)
continue

language_files = files.getFiles(source)

files_to_upload.append(language_files['found'])
Expand Down Expand Up @@ -196,6 +229,9 @@ def uploadFiles(upload_files, force=False, draft=False, debug=False):
if 'tag' in file_data:
send_data['tag'] = file_data['tag']

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

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

Expand Down Expand Up @@ -251,6 +287,8 @@ def uploadFile(file_data, force=False, draft=False, debug=False):
if 'tag' in file_data:
request_data['tag'] = file_data['tag']

if 'key_prefix' in file_data:
request_data['addKeyPrefix'] = file_data['key_prefix']

return makeRequest(data=request_data, api_path='/files', upload_file=file_data['path'], method='POST', debug=debug)
except ApplangaRequestException as e:
Expand Down
2 changes: 1 addition & 1 deletion lib/constants.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION_NUMBER = '1.0.75'
VERSION_NUMBER = '1.0.76'
APPLANGA_HOST = 'https://api.applanga.com'
API_BASE_PATH = '/v1/api'
CONFIG_FILE_NAME = '.applanga.json'
Expand Down
2 changes: 2 additions & 0 deletions lib/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ def getFiles(source):
return_files[file]['tag'] = source['tag']
if 'file_format' in source:
return_files[file]['file_format'] = source['file_format']
if 'key_prefix' in source:
return_files[file]['key_prefix'] = source['key_prefix']

if 'disable_plurals' in source:
return_files[file]['disable_plurals'] = source['disable_plurals']
Expand Down

0 comments on commit 3c4afb2

Please sign in to comment.