-
Notifications
You must be signed in to change notification settings - Fork 458
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve i18n support #1162
Open
jcfr
wants to merge
5
commits into
Slicer:master
Choose a base branch
from
jcfr:improve-i18n-support
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Improve i18n support #1162
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3698db6
ENH: Support for scripted module internationalization
jcfr 53f379c
ENH: i18n: Add GenerateSlicerTranslationQMFiles target
jcfr 3b6e3ff
STYLE: i18n: Simplify buildsystem removing RewritePythonScriptsForTra…
jcfr 5684447
ENH: i18n: Add support for generating translation templates
jcfr 71e06d4
STYLE: i18n: Simplify *.ts files removing location
jcfr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
def tr(context, text): | ||
from slicer import app | ||
return app.translate(context, text) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import ast | ||
import errno | ||
import getopt | ||
import os | ||
import sys | ||
|
||
import astor | ||
|
||
|
||
class RewriteTr(ast.NodeTransformer): | ||
"""Replace tr to QT_TRANSLATE_NOOP | ||
""" | ||
def visit_Call(self, node): | ||
self.generic_visit(node) | ||
# Transform 'tr' into 'QT_TRANSLATE_NOOP' """ | ||
if (isinstance(node.func, ast.Name) and \ | ||
("tr" == node.func.id) and \ | ||
len(node.args) == 2): | ||
call = ast.Call(func=ast.Name(id='QT_TRANSLATE_NOOP', ctx=ast.Load()), | ||
args=node.args, | ||
keywords=[]) | ||
ast.copy_location(call, node) | ||
# Add lineno & col_offset to the nodes we created | ||
ast.fix_missing_locations(call) | ||
return call | ||
|
||
# Return the original node if we don't want to change it. | ||
return node | ||
|
||
|
||
def mkdir_p(path): | ||
"""Ensure directory ``path`` exists. If needed, parent directories | ||
are created. | ||
Adapted from http://stackoverflow.com/a/600612/1539918 | ||
""" | ||
try: | ||
os.makedirs(path) | ||
except OSError as exc: # Python >2.5 | ||
if exc.errno == errno.EEXIST and os.path.isdir(path): | ||
pass | ||
else: # pragma: no cover | ||
raise | ||
|
||
|
||
def main(argv): | ||
|
||
input_file = '' | ||
output_file = '' | ||
try: | ||
opts, args = getopt.getopt(argv, "hi:o:", ["ifile=","ofile="]) | ||
except getopt.GetoptError: | ||
print('RewriteTr.py -i <inputfile> -o <outputfile>') | ||
sys.exit(2) | ||
for opt, arg in opts: | ||
if opt == '-h': | ||
print('RewriteTr.py -i <inputfile> -o <outputfile>') | ||
sys.exit() | ||
elif opt in ("-i", "--ifile"): | ||
input_file = arg | ||
elif opt in ("-o", "--ofile"): | ||
output_file = arg | ||
|
||
with open(input_file, "r") as source: | ||
tree = ast.parse(source.read()) | ||
|
||
tree_new = RewriteTr().visit(tree) | ||
all_lines = astor.to_source(tree_new) | ||
|
||
# if needed, create output directory | ||
output_dir = os.path.dirname(output_file) | ||
#print("output_dir [%s]" % output_dir) | ||
mkdir_p(output_dir) | ||
|
||
# replace the single quotation marks to double quotation marks. It is necessary for lupdate | ||
with open(output_file, "w") as destination: | ||
for line in all_lines: | ||
linenew = line.replace('\'', "\"") | ||
destination.write(linenew) | ||
|
||
|
||
if __name__ == "__main__": | ||
main(sys.argv[1:]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does this function (and the whole file) do?