Skip to content

Commit

Permalink
Merge pull request #305 from tableau/jac/collect-missed-strings
Browse files Browse the repository at this point in the history
fix glob reference to find strings in code
  • Loading branch information
jacalata authored Aug 17, 2024
2 parents f3337f2 + 143a83a commit e1f80d3
Show file tree
Hide file tree
Showing 13 changed files with 15 additions and 11 deletions.
4 changes: 2 additions & 2 deletions bin/i18n/msgfmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def make(filename, outfile):
CTXT = 3

encoding = 'utf-8'
print("Assumed encoding", encoding)
print("msgfmt::Assumed encoding", encoding)

# Compute .mo name from .po name and arguments
if filename.endswith('.po'):
Expand Down Expand Up @@ -196,7 +196,7 @@ def make(filename, outfile):
try:
l = ast.literal_eval(l)
except:
print("ERROR (skipped)", lno, msgid)
print("\tERROR (skipped)", lno, msgid)
pass
if section == CTXT:
msgctxt += l.encode(encoding)
Expand Down
22 changes: 13 additions & 9 deletions dodo.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,22 @@ def task_properties():
def process_code():
print("\n***** Collect all string keys used in code")

CODE_PATH = "tabcmd/[ec]*/**/*.py"
CODE_PATH = "tabcmd/**/*.py"
STRINGS_FILE = "tabcmd/locales/codestrings.properties"
STRING_FLAG = '_("'
STRING_END = '")'

lines = set([])
with open(STRINGS_FILE, "w+", encoding="utf-8") as stringfile:
for codefile in glob.glob(CODE_PATH):
for codefile in glob.glob(CODE_PATH, recursive=True):
print("\t" + codefile)
with open(codefile, encoding="utf-8") as infile:
# find lines that contain a loc string in the form _("string goes here")
for line in infile:
i = line.find(STRING_FLAG)
# include only the string itself and the quote symbols around it
if i >= 0:
# print(line)
j = line.find(STRING_END)
lines.add(line[i + 3 : j] + "\n")

Expand All @@ -66,7 +68,7 @@ def merge():
# U201C, U201D and U201E - opening quotes, German opening quotes, and closing quotes
import re

changed_input = re.sub("[\u201c\u201d\u201e]", input)
changed_input = re.sub("[\u201c\u201d\u201e]", "'", input)
# some strings for some reason use two single quotes as a double quote. Reduce to one single quote.
re_changed_input = re.sub("''", "'", changed_input)
outfile.write(re_changed_input)
Expand Down Expand Up @@ -96,6 +98,8 @@ def filter():
key = line.split("=")[0]
if key in required:
outfile.writelines(line)
else:
print("\tExcluding {}".format(key))

print("Filtered strings for {}".format(current_locale))

Expand Down Expand Up @@ -246,7 +250,7 @@ def generate_mo():

LOC_PATH = "tabcmd/locales/" + current_locale + "/LC_MESSAGES"

print("\twriting final {}/tabcmd.mo file".format(current_locale))
print("\nBegin writing final {}/tabcmd.mo file".format(current_locale))
# build the single binary file from the .po file
# a number of keys are failing at the write-to-mo step. We don't use any of them so that's fine for now.
result = subprocess.run(["python", "bin/i18n/msgfmt.py", LOC_PATH + "/tabcmd"])
Expand All @@ -270,16 +274,17 @@ def check_mo():
LOC_DIR = os.path.join(LANG_DIR, current_locale, "LC_MESSAGES")
MO_FILE = os.path.join(LOC_DIR, "tabcmd.mo")
domain = "tabcmd"
print("\tloading {} file to validate".format(MO_FILE))
print("Loading {} file to validate".format(MO_FILE))
try:
with open(MO_FILE, "rb") as fp:
print("\topened file - now calling translate {}".format(current_locale))
print("File open - now calling translate ({})".format(current_locale))
language: gettext.NullTranslations = gettext.translation(
domain, LANG_DIR, languages=[current_locale]
)
language.install()
_ = language.gettext
print(_("common.output.succeeded"))
print("\t" + _("common.output.succeeded"))
print("\t" + _("session.options.server"))
except Exception as e:
print(e)

Expand Down Expand Up @@ -325,13 +330,12 @@ def uniquify_file(filename):
lines = my_file.readlines()
for line in lines:
line = line.strip()
line = line.strip('"')
# lines cannot extend over two lines.
line = line.replace("\\n", " ")
if line == "":
continue
elif "=" not in line and "codestrings" not in filename:
print("prop2po will not like this line. Discarding [{}]".format(line))
print("\tprop2po will not like this line. Discarding [{}]".format(line))
continue
else:
uniques.add(line + "\n")
Expand Down
Binary file modified tabcmd/locales/de/LC_MESSAGES/tabcmd.mo
Binary file not shown.
Binary file modified tabcmd/locales/en/LC_MESSAGES/tabcmd.mo
Binary file not shown.
Binary file modified tabcmd/locales/es/LC_MESSAGES/tabcmd.mo
Binary file not shown.
Binary file modified tabcmd/locales/fr/LC_MESSAGES/tabcmd.mo
Binary file not shown.
Binary file modified tabcmd/locales/ga/LC_MESSAGES/tabcmd.mo
Binary file not shown.
Binary file modified tabcmd/locales/it/LC_MESSAGES/tabcmd.mo
Binary file not shown.
Binary file modified tabcmd/locales/ja/LC_MESSAGES/tabcmd.mo
Binary file not shown.
Binary file modified tabcmd/locales/ko/LC_MESSAGES/tabcmd.mo
Binary file not shown.
Binary file modified tabcmd/locales/pt/LC_MESSAGES/tabcmd.mo
Binary file not shown.
Binary file modified tabcmd/locales/sv/LC_MESSAGES/tabcmd.mo
Binary file not shown.
Binary file modified tabcmd/locales/zh/LC_MESSAGES/tabcmd.mo
Binary file not shown.

0 comments on commit e1f80d3

Please sign in to comment.