Skip to content

Commit

Permalink
Don't add string source comments by default
Browse files Browse the repository at this point in the history
  • Loading branch information
Wuzzy2 committed Mar 16, 2021
1 parent a3cbe6b commit 86d970a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ i18n.py [OPTIONS] [PATHS...]
--no-old-file, -O: do not create *.old files
--sort, -s: sort output strings alphabetically
--break-long-lines, -b: add extra line-breaks before and after long strings
--print-source, -p: add comments denoting the soure file
--verbose, -v: add output information
```

Expand Down
13 changes: 10 additions & 3 deletions bash-completion/completions/i18n
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
_i18n_completions()
{
local cur OPTS_ALL
local hasInstalledModOpt hasRecursiveOpt hasVerboseOpt hasNoOldFileOpt hasSortOpt hasBreakLongLinesOpt
local hasInstalledModOpt hasRecursiveOpt hasVerboseOpt hasNoOldFileOpt hasSortOpt hasBreakLongLinesOpt hasPrintSourceOpt
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
for opt in "${COMP_WORDS[@]}"
Expand All @@ -29,7 +29,9 @@ _i18n_completions()
'-b'|'--break-long-lines')
hasBreakLongLinesOpt=1
;;

'-p'|'--print-source')
hasPrintSourceOpt=1
;;
esac
done
case $cur in
Expand All @@ -40,7 +42,8 @@ _i18n_completions()
--verbose
--no-old-file
--sort
--break-long-lines"
--break-long-lines
--print-source"

# recursive and installed-mods
# are mutually exclusives
Expand All @@ -65,6 +68,10 @@ _i18n_completions()
then
OPTS_ALL=${OPTS_ALL//"--break-long-lines"/}
fi
if [ $hasPrintSourceOpt]
then
OPTS_ALL=${OPTS_ALL//"--print-source"/}
fi

COMPREPLY=( $(compgen -W "${OPTS_ALL[*]}" -- $cur) )
return 0
Expand Down
17 changes: 10 additions & 7 deletions i18n.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"folders": [],
"no-old-file": False,
"break-long-lines": False,
"sort": False
"sort": False,
"print-source": False
}
# Available CLI options
options = {"recursive": ['--recursive', '-r'],
Expand All @@ -32,7 +33,8 @@
"verbose": ['--verbose', '-v'],
"no-old-file": ['--no-old-file', '-O'],
"break-long-lines": ['--break-long-lines', '-b'],
"sort": ['--sort', '-s']
"sort": ['--sort', '-s'],
"print-source": ['--print-source', '-p']
}

# Strings longer than this will have extra space added between
Expand Down Expand Up @@ -229,7 +231,7 @@ def mkdir_p(path):
# dOld is a dictionary of existing translations and comments from
# the previous version of this text
def strings_to_text(dkeyStrings, dOld, mod_name, header_comments):
lOut = [f"# textdomain: {mod_name}\n"]
lOut = [f"# textdomain: {mod_name}"]
if header_comments is not None:
lOut.append(header_comments)

Expand All @@ -250,16 +252,17 @@ def strings_to_text(dkeyStrings, dOld, mod_name, header_comments):
localizedStrings = dGroupedBySource[source]
if params["sort"]:
localizedStrings.sort()
lOut.append("")
lOut.append(source)
lOut.append("")
if params["print-source"]:
if lOut[-1] != "":
lOut.append("")
lOut.append(source)
for localizedString in localizedStrings:
val = dOld.get(localizedString, {})
translation = val.get("translation", "")
comment = val.get("comment")
if params["break-long-lines"] and len(localizedString) > doublespace_threshold and not lOut[-1] == "":
lOut.append("")
if comment != None:
if comment != None and comment != "" and not comment.startswith("# textdomain:"):
lOut.append(comment)
lOut.append(f"{localizedString}={translation}")
if params["break-long-lines"] and len(localizedString) > doublespace_threshold:
Expand Down

0 comments on commit 86d970a

Please sign in to comment.