Skip to content

Commit

Permalink
Merge pull request #302 from tableau/jac/string-localization
Browse files Browse the repository at this point in the history
Add a large number of new localized strings
  • Loading branch information
jacalata authored Jul 24, 2024
2 parents 592321b + c53ff99 commit f3337f2
Show file tree
Hide file tree
Showing 115 changed files with 4,989 additions and 75,686 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,14 @@ pytest.xml
# doit
.doit.*

# localization intermediate files
*.po

# venv
site-packages

# local
tabcmd-dev
workon
test.junit.xml
*.out
5 changes: 3 additions & 2 deletions bin/i18n/msgfmt.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#! /usr/bin/env python3
# Written by Martin v. Löwis <[email protected]>

""" Updated to handle utf-8 files and give better error messages
"""
Fetched from https://github.com/python/cpython/blob/main/Tools/i18n/msgfmt.py
Updated to handle utf-8 files and give better error messages
TODO contribute back?
"""

Expand Down
29 changes: 18 additions & 11 deletions bin/i18n/prop2po.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,51 @@
"""

import click

from datetime import datetime

@click.command()
@click.argument('source', type=click.File('rt', encoding='utf-8'))
@click.argument('destination', type=click.File('wt', encoding='utf-8'))
@click.option('-l', '--language', type=click.STRING, help='The translation language')
@click.option('-p', '--project', type=click.STRING, help='The name of the project')
@click.option('-e', '--encoding', type=click.STRING, help='The encoding wanted')
def to_po(source, destination, encoding, language, project):
@click.option('-c', '--copyright', type=click.STRING, help='The person/organization holding copyright')
def to_po(source, destination, encoding, language, project, copyright):
"""Converts a property file to a Gettext PO file.
SOURCE is the path of the property file to convert.
DESTINATION is the path of the Gettext PO file to create
"""

year = datetime.now().strftime('%Y')
header = """msgid ""
msgstr ""
"MIME-Version: 1.0\\n"
"Content-Type: text/plain; charset={encoding}\\n"
"MIME-Version: 1.0\\n\\n"
"Content-Type: text/plain; charset={encoding}\\n\\n"
"Content-Transfer-Encoding: 8bit\\n"
"X-Generator: prop2po\\n"
"Project-Id-Version: {project}\\n"
"Language: {language}\\n"
# Copyright (C) YEAR Tableau Software
"""
# Copyright (C) {year} {copyright}
"""

lines = source.readlines()
print(lines)
destination.write(header.format(
language=language,
project=project,
encoding=encoding
encoding=encoding,
year=year,
copyright=copyright
))
for line in lines:
if not line.isspace():
parts = line.split('=')
# Split only on the first instance of '=' so that the character can also appear in the string
parts = line.split('=', 1)
# TODO it fails on comments/lines with less than two parts after splitting
destination.write('#:\n' + 'msgid "' + parts[0] + '"\n' 'msgstr "' + parts[1][:-1] + '"\n\n')
try:
destination.write('#:\n' + 'msgid "' + parts[0] + '"\n' 'msgstr "' + parts[1][:-1] + '"\n\n')
except IndexError as e:
print("FAILED on line{}".format(line))


if __name__ == '__main__':
Expand Down
13 changes: 9 additions & 4 deletions contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,15 @@ _(note that running mypy and black with no errors is required before code will b
> You can only build an executable for the platform you are running pyinstaller on. The spec for each platform is stored in tabcmd-*platform*.spec and the exact build commands for each platform can be checked in [our packaging script](.github/workflows//package.yml).
e.g for Windows
> pyinstaller tabcmd-windows.spec --clean --noconfirm --distpath ./dist/windows
> pyinstaller tabcmd-windows.spec --clean --distpath .\dist\windows
produces dist/tabcmd.exe
produces dist\windows\tabcmd.exe
To run the newly created executable, from a console window in the same directory as the file tabcmd.py:
> dist/tabcmd/tabcmd.exe --help
> dist\windows\tabcmd.exe --help
> dist\windows\tabcmd.exe publish --country FR --language FR cookie.twbx
To investigate what's packaged in the executable, use https://pyinstxtractor-web.netlify.app/
Expand All @@ -128,7 +131,9 @@ Strings are stored in /tabcmd/locales/[language]/*.properties by id and referred
> string = _("string.id")
For runtime execution these files must be converted from .properties -> .po -> .mo files. These .mo files will be bundled in the the package by pyinstaller. The entire conversion action is done by a .doit script:
> doit mo
> doit properties po mo
You can also check that there are no malformed/forgotten message keys in the code with
> doit strings
### Versioning
Expand Down
Loading

0 comments on commit f3337f2

Please sign in to comment.