diff options
author | Caroline Chao <caroline.chao@digia.com> | 2014-02-19 17:29:51 +0100 |
---|---|---|
committer | Caroline Chao <caroline.chao@digia.com> | 2014-03-04 15:53:10 +0100 |
commit | bc8379394344ddc6d039944da90f59d1ecebc76e (patch) | |
tree | e5bee596268e8fda493cf18e7ff51a5d5b99e044 /weatherapp.pro | |
parent | 2117732be5762810e58fbf6cf576440f1b3a8166 (diff) |
Add Localizations to the weather app
Use application's locale to load the relevant translation if available.
Automate the run of lrelease to generate the translation files *.qm
for each language available. Embed the *qm files in the application.
Add ts-<lang> and commit-ts targets for convenience while dealing with
translations files.
Change-Id: I9ff96fb8468a04f4657e425c2c9c730cbcc4481f
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
Diffstat (limited to 'weatherapp.pro')
-rw-r--r-- | weatherapp.pro | 77 |
1 files changed, 76 insertions, 1 deletions
diff --git a/weatherapp.pro b/weatherapp.pro index a386a5d..2b524a8 100644 --- a/weatherapp.pro +++ b/weatherapp.pro @@ -40,7 +40,36 @@ APP_FILES += \ $$PWD/fonts/OpenSans-Semibold.ttf \ $$PWD/fonts/OpenSans-Regular.ttf -OTHER_FILES += $$APP_FILES +OTHER_FILES += $$APP_FILES $$PWD/translations/README + +# var, prepend, append +defineReplace(prependAll) { + for(a,$$1):result += $$2$${a}$$3 + return($$result) +} + +# Supported languages +LANGUAGES = + +# Available translations +TRANSLATIONS = $$prependAll(LANGUAGES, $$PWD/translations/QuickForecast_, .ts) + +# Used to embed the qm files in resources +TRANSLATIONS_FILES = + +# run LRELEASE to generate the qm files +qtPrepareTool(LRELEASE, lrelease) +for(tsfile, TRANSLATIONS) { + qmfile = $$shadowed($$tsfile) + qmfile ~= s,\\.ts$,.qm, + qmdir = $$dirname(qmfile) + !exists($$qmdir) { + mkpath($$qmdir)|error("Aborting.") + } + command = $$LRELEASE -removeidentical $$tsfile -qm $$qmfile + system($$command)|error("Failed to run: $$command") + TRANSLATIONS_FILES += $$qmfile +} # Create the resource file GENERATED_RESOURCE_FILE = $$OUT_PWD/weatherapp.qrc @@ -56,6 +85,11 @@ for(resourcefile, APP_FILES) { RESOURCE_CONTENT += "<file alias=\"weatherapp/$$relativepath_in\">$$relativepath_out</file>" } +for(translationfile, TRANSLATIONS_FILES) { + relativepath_out = $$relative_path($$translationfile, $$OUT_PWD) + RESOURCE_CONTENT += "<file alias=\"$$relativepath_out\">$$relativepath_out</file>" +} + RESOURCE_CONTENT += \ "</qresource>" \ "</RCC>" @@ -72,3 +106,44 @@ ios { } android: ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android + +# TRANSLATIONS - Create extra targets for convenience + +wd = $$replace(PWD, /, $$QMAKE_DIR_SEP) + +# LUPDATE - Make new targets for each and all languages +qtPrepareTool(LUPDATE, lupdate) +LUPDATE += -locations relative -no-ui-lines +TSFILES = $$files($$PWD/translations/QuickForecast_*.ts) $$PWD/translations/QuickForecast_untranslated.ts +for(file, TSFILES) { + lang = $$replace(file, .*_([^/]*)\\.ts, \\1) + v = ts-$${lang}.commands + $$v = cd $$wd && $$LUPDATE $$SOURCES $$APP_FILES -ts $$file + QMAKE_EXTRA_TARGETS += ts-$$lang +} +ts-all.commands = cd $$PWD && $$LUPDATE $$SOURCES $$APP_FILES -ts $$TSFILES +QMAKE_EXTRA_TARGETS += ts-all + +# COMMIT - Make a new target for lconvert and committing the ts files +# lconvert is used to remove the strings location in the ts files +# and thus save space. +qtPrepareTool(LCONVERT, lconvert) +LCONVERT += -locations none +isEqual(QMAKE_DIR_SEP, /) { + commit-ts.commands = \ + cd $$wd; \ + git add -N translations/*_??.ts && \ + for f in `git diff-files --name-only translations/*_??.ts`; do \ + $$LCONVERT -i \$\$f -o \$\$f; \ + done; \ + git add translations/*_??.ts && git commit +} else { + commit-ts.commands = \ + cd $$wd && \ + git add -N translations/*_??.ts && \ + for /f usebackq %%f in (`git diff-files --name-only -- translations/*_??.ts`) do \ + $$LCONVERT -i %%f -o %%f $$escape_expand(\\n\\t) \ + cd $$wd && git add translations/*_??.ts && git commit +} +QMAKE_EXTRA_TARGETS += commit-ts + |