Skip to content

Commit

Permalink
add __CUTTING_LENGTH_RATIO__
Browse files Browse the repository at this point in the history
  • Loading branch information
metasmile committed Jul 23, 2018
1 parent b24b0ad commit d65fcf1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,8 @@ optional arguments:
Keys in the strings to update and translate by force.
-o, --following-base-keys
Keys in the strings to follow from "Base".
-l, --following-base-keys-if-length-longer
Keys in the strings to follow from "Base"
if its length longer than the length of "Base" value.
-l, --cutting-length-ratio-with-base
Keys in the float as the ratio to compare the length of "Base"
-c, --ignore-comments
Allows ignoring comment synchronization.
-v, --verify-results
Expand Down
11 changes: 6 additions & 5 deletions strsync/strsync.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +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('-l', '--following-base-keys-if-length-longer', type=str,
help='Keys in the strings to follow from "Base" if its length longer than length of "Base" value.',
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='+')
parser.add_argument('-c', '--ignore-comments', help='Allows ignoring comment synchronization.', default=None,
required=False, nargs='*')
Expand Down Expand Up @@ -80,7 +80,8 @@ def main():
__KEYS_FORCE_TRANSLATE__ = args['force_translate_keys']
__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']
__KEYS_FOLLOW_BASE_IF_LENGTH_LONGER__ = args['following_base_keys_if_length_longer']
__CUTTING_LENGTH_RATIO__ = (args['cutting_length_ratio_with_base'] or [0])[0]

__IGNORE_COMMENTS__ = args['ignore_comments'] is not None
__IGNORE_UNVERIFIED_RESULTS__ = args['ignore_unverified_results'] is not None
__RATIO_TO_IGNORE_UNVERIFIED_RESULTS__ = int(
Expand Down Expand Up @@ -235,10 +236,10 @@ def insert_or_translate(target_file, lc):
# exists
elif k in existing_keys:

if k in __KEYS_FOLLOW_BASE_IF_LENGTH_LONGER__:
if k != "Base" and __CUTTING_LENGTH_RATIO__>0:

if target_value != base_kv[k] \
and len_unicode(target_value) > len_unicode(base_kv[k]) \
and len_unicode(target_value) > float(len_unicode(base_kv[k]))*__CUTTING_LENGTH_RATIO__ \
or needs_update_comment:

print(Fore.YELLOW + '(!) Length of "', target_value, '" is longer than"', base_kv[k], '" as',
Expand Down

0 comments on commit d65fcf1

Please sign in to comment.