diff --git a/CHANGELOG.md b/CHANGELOG.md index d33be7f..dfb1852 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ *Applanga CLI Documentation:* *** +### 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 diff --git a/README.md b/README.md index 4508baa..2011be9 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Applanga Localization Command Line Interface (CLI) *** -*Version:* 1.0.75 +*Version:* 1.0.76 *Website:* @@ -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 applanga@1.0.75 + brew install applanga@1.0.76 ``` ##### Github @@ -370,6 +370,16 @@ It is possible to set the variable `` 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 --- diff --git a/lib/api.py b/lib/api.py index bbb7c0d..6172918 100644 --- a/lib/api.py +++ b/lib/api.py @@ -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 @@ -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 @@ -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) @@ -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']) @@ -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'] @@ -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: diff --git a/lib/constants.py b/lib/constants.py index f568553..3f3c3ab 100644 --- a/lib/constants.py +++ b/lib/constants.py @@ -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' diff --git a/lib/files.py b/lib/files.py index 8b815b6..90df5c3 100644 --- a/lib/files.py +++ b/lib/files.py @@ -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']