Skip to content

Commit

Permalink
rewrite localization script
Browse files Browse the repository at this point in the history
  • Loading branch information
chriba committed Sep 19, 2016
1 parent d40f9f4 commit 6175988
Show file tree
Hide file tree
Showing 6 changed files with 459 additions and 261 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,6 @@ bin/
jabref.xml
install4j6/
*.sonargraph

# ignore the generated markdown file if the user forgets to delete it
status.md
33 changes: 17 additions & 16 deletions localization.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,48 +10,49 @@ dependencies {
jython 'org.python:jython-standalone:2.7.0'
}

task checkTranslations(type: JavaExec) {
description "Print empty and duplicate translations."
task statusWithMarkdown(type: JavaExec) {
description "Creates an update file in Markdown"
group = 'Localization'
main 'org.python.util.jython'
classpath project.configurations.jython.asPath
args file("scripts/syncLang.py")
args "-d"
args "markdown"
}

task checkTranslationsSummary(type: JavaExec) {
description "Print summary of empty and duplicate translations."
task status(type: JavaExec) {
description "Prints the current status"
group = 'Localization'
main 'org.python.util.jython'
classpath project.configurations.jython.asPath
args file("scripts/syncLang.py")
args "-c"
args "status"
}

task showMissingTranslationKeys(type: JavaExec) {
description "Prints differences between the English translation and translations in other languages."
task statusExtended(type: JavaExec) {
description "Prints the current status (extended output)"
group = 'Localization'
main 'org.python.util.jython'
classpath project.configurations.jython.asPath
args file("scripts/syncLang.py")
args "-t"
args "status"
args "--extended"
}

task generateMissingTranslationKeys(type: JavaExec) {
description "Prints differences between the English translation and translations in other languages, and updates translations if possible."
task update(type: JavaExec) {
description "Updates the localization files (fixes duplicates, adds missing keys, and sort them"
group = 'Localization'
main 'org.python.util.jython'
classpath project.configurations.jython.asPath
args file("scripts/syncLang.py")
args "-t"
args "-u"
args "update"
}

task sortKeysInTranslationFiles(type: JavaExec) {
description "Sorts the the keys in all localization Files according to the key order in the english files"
task updateExtended(type: JavaExec) {
description "Updates the localization files (fixes duplicates, adds missing keys, and sort them (extended output)"
group = 'Localization'
main 'org.python.util.jython'
classpath project.configurations.jython.asPath
args file("scripts/syncLang.py")
args "-s"
args "update"
args "--extended"
}
4 changes: 4 additions & 0 deletions scripts/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
jq
jq.exe

# python
*.pyc
*$py.class
23 changes: 23 additions & 0 deletions scripts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Script usage

The Script has following commands available
- `$ python scripts/syncLang.py status [--extended]`
- prints the current status to the terminal
- `[--extended]` if the translations keys which create problems should be printed
- usable with Gradle tasks
- `$ gradle status`
- `$ gradle statusExtended`


- `$ python scripts/syncLang.py markdown`
- Creates a markdown file of the current status and opens it
- usable with Gradle tasks
- `$ gradle statusWithMarkdown`


- `$ python scripts/syncLang.py update [--extended]`
- compares all the localization files against the English one and fixes unambiguous duplicates, removes obsolete keys, adds missing keys, and sorts them
- `[--extended]` if the translations keys which create problems should be printed
- usable with Gradle tasks
- `$ gradle update`
- `$ gradle updateExtended`
29 changes: 29 additions & 0 deletions scripts/logger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
def enum(**enums):
return type('Enum', (), enums)


OUTPUT_COLORS = enum(
OK='\033[0;32m',
WARN='\033[0;33m',
ERROR='\033[0;31m',
ENDC='\033[0;38m'
)


def error(content):
print "{color_error}{content}{color_end}" \
.format(color_error=OUTPUT_COLORS.ERROR, content=str(content), color_end=OUTPUT_COLORS.ENDC)


def warn(content):
print "{color_error}{content}{color_end}" \
.format(color_error=OUTPUT_COLORS.WARN, content=str(content), color_end=OUTPUT_COLORS.ENDC)


def ok(content):
print "{color_error}{content}{color_end}" \
.format(color_error=OUTPUT_COLORS.OK, content=str(content), color_end=OUTPUT_COLORS.ENDC)


def neutral(content):
print content
Loading

0 comments on commit 6175988

Please sign in to comment.