Skip to content

Commit

Permalink
add option -w , --following-base-if-not-exists
Browse files Browse the repository at this point in the history
  • Loading branch information
metasmile committed Sep 20, 2018
1 parent cec43b1 commit de2a5ab
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 19 deletions.
50 changes: 34 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,37 +36,55 @@ pip install requests[security]
Naturally, this tool follow [standard ISO639 1~2 codes](http://www.loc.gov/standards/iso639-2/php/English_list.php) or [apple's official document](https://developer.apple.com/library/ios/documentation/MacOSX/Conceptual/BPInternational/LanguageandLocaleIDs/LanguageandLocaleIDs.html) or [this tsv table](https://github.com/metasmile/strsync/blob/master/strsync/lc_ios9.tsv)

```
usage: strsync <target localization resource path>
Automatically translate and synchronize .strings files from defined base language.
usage: strsync-runner.py [-h] [-b BASE_LANG_NAME]
[-x EXCLUDING_LANG_NAMES [EXCLUDING_LANG_NAMES ...]]
[-f [FORCE_TRANSLATE_KEYS [FORCE_TRANSLATE_KEYS ...]]]
[-o FOLLOWING_BASE_KEYS [FOLLOWING_BASE_KEYS ...]]
[-w [FOLLOWING_BASE_IF_NOT_EXISTS [FOLLOWING_BASE_IF_NOT_EXISTS ...]]]
[-l CUTTING_LENGTH_RATIO_WITH_BASE [CUTTING_LENGTH_RATIO_WITH_BASE ...]]
[-c [IGNORE_COMMENTS [IGNORE_COMMENTS ...]]]
[-v [VERIFY_RESULTS [VERIFY_RESULTS ...]]]
[-s [INCLUDE_SECONDARY_LANGUAGES [INCLUDE_SECONDARY_LANGUAGES ...]]]
[-i [IGNORE_UNVERIFIED_RESULTS [IGNORE_UNVERIFIED_RESULTS ...]]]
[target path]
Automatically translate and synchronize .strings files from defined base
language.
positional arguments:
target path Target localization resource path. (root path of
Base.lproj, default=./)
optional arguments:
-h, --help show this help message and exit
-b, --base-lang-name BASE_LANG_NAME
-b BASE_LANG_NAME, --base-lang-name BASE_LANG_NAME
A base(or source) localizable resource
name.(default='Base'), (e.g. "Base" via 'Base.lproj',
"en" via 'en.lproj')
-x, --excluding-lang-names
-x EXCLUDING_LANG_NAMES [EXCLUDING_LANG_NAMES ...], --excluding-lang-names EXCLUDING_LANG_NAMES [EXCLUDING_LANG_NAMES ...]
A localizable resource name that you want to exclude.
(e.g. "Base" via 'Base.lproj', "en" via 'en.lproj')
-f, --force-translate-keys
-f [FORCE_TRANSLATE_KEYS [FORCE_TRANSLATE_KEYS ...]], --force-translate-keys [FORCE_TRANSLATE_KEYS [FORCE_TRANSLATE_KEYS ...]]
Keys in the strings to update and translate by force.
-o, --following-base-keys
Keys in the strings to follow from "Base".
-l, --cutting-length-ratio-with-base
Keys in the float as the ratio to compare the length of "Base"
-c, --ignore-comments
(input nothing for all keys.)
-o FOLLOWING_BASE_KEYS [FOLLOWING_BASE_KEYS ...], --following-base-keys FOLLOWING_BASE_KEYS [FOLLOWING_BASE_KEYS ...]
Keys in the strings to follow from "Base.
-w [FOLLOWING_BASE_IF_NOT_EXISTS [FOLLOWING_BASE_IF_NOT_EXISTS ...]], --following-base-if-not-exists [FOLLOWING_BASE_IF_NOT_EXISTS [FOLLOWING_BASE_IF_NOT_EXISTS ...]]
With this option, all keys will be followed up with
base values if they does not exist.
-l CUTTING_LENGTH_RATIO_WITH_BASE [CUTTING_LENGTH_RATIO_WITH_BASE ...], --cutting-length-ratio-with-base CUTTING_LENGTH_RATIO_WITH_BASE [CUTTING_LENGTH_RATIO_WITH_BASE ...]
Keys in the float as the ratio to compare the length
of "Base"
-c [IGNORE_COMMENTS [IGNORE_COMMENTS ...]], --ignore-comments [IGNORE_COMMENTS [IGNORE_COMMENTS ...]]
Allows ignoring comment synchronization.
-v, --verify-results
-v [VERIFY_RESULTS [VERIFY_RESULTS ...]], --verify-results [VERIFY_RESULTS [VERIFY_RESULTS ...]]
Verify translated results via reversed results
-i, --ignore-unverified-results
Allows ignoring unverified results when appending them.
-s, --include-secondary-languages
Include Additional Secondary Languages. (+63 language codes)
-s [INCLUDE_SECONDARY_LANGUAGES [INCLUDE_SECONDARY_LANGUAGES ...]], --include-secondary-languages [INCLUDE_SECONDARY_LANGUAGES [INCLUDE_SECONDARY_LANGUAGES ...]]
Include Additional Secondary Languages. (+63 language
codes)
-i [IGNORE_UNVERIFIED_RESULTS [IGNORE_UNVERIFIED_RESULTS ...]], --ignore-unverified-results [IGNORE_UNVERIFIED_RESULTS [IGNORE_UNVERIFIED_RESULTS ...]]
Allows ignoring unverified results when appending
them.
```

### Examples to use
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

setup(
name="strsync",
version="1.4.7",
version="1.4.8",
packages=[
'strsync',
],
Expand Down
10 changes: 8 additions & 2 deletions strsync/strsync.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ def main():
default=[], required=False, nargs='*')
parser.add_argument('-o', '--following-base-keys', type=str, help='Keys in the strings to follow from "Base.',
default=[], required=False, nargs='+')
parser.add_argument('-w', '--following-base-if-not-exists', type=str, help='With this option, all keys will be followed up with base values if they does not exist.',
default=None, required=False, nargs='*')
parser.add_argument('-l', '--cutting-length-ratio-with-base', type=float,
help='Keys in the float as the ratio to compare the length of "Base"',
default=[], required=False, nargs='+')
Expand Down Expand Up @@ -81,6 +83,7 @@ def main():
__KEYS_FORCE_TRANSLATE_ALL__ = ('--force-translate-keys' in sys.argv or '-f' in sys.argv) and not __KEYS_FORCE_TRANSLATE__
__KEYS_FOLLOW_BASE__ = args['following_base_keys']
__CUTTING_LENGTH_RATIO__ = (args['cutting_length_ratio_with_base'] or [0])[0]
__FOLLOWING_ALL_KEYS_IFNOT_EXIST__ = args['following_base_if_not_exists'] is not None

__IGNORE_COMMENTS__ = args['ignore_comments'] is not None
__IGNORE_UNVERIFIED_RESULTS__ = args['ignore_unverified_results'] is not None
Expand Down Expand Up @@ -171,9 +174,12 @@ def insert_or_translate(target_file, lc):
base_kc[k] = item['comment']

force_adding_keys = base_kv.keys() if __KEYS_FORCE_TRANSLATE_ALL__ else __KEYS_FORCE_TRANSLATE__

adding_keys = list(
((set(base_kv.keys()) - set(target_kv.keys())) | (set(base_kv.keys()) & set(force_adding_keys))) - set(
__KEYS_FOLLOW_BASE__))
((set(base_kv.keys()) - set(target_kv.keys())) | (set(base_kv.keys()) & set(force_adding_keys))) \
- set(base_kv.keys() if __FOLLOWING_ALL_KEYS_IFNOT_EXIST__ else __KEYS_FOLLOW_BASE__) \
)

removing_keys = list(set(target_kv.keys()) - set(base_kv.keys()))
existing_keys = list(set(base_kv.keys()) - (set(adding_keys) | set(removing_keys)))
updated_keys = []
Expand Down

0 comments on commit de2a5ab

Please sign in to comment.