1
# This include file makes generation and installation of .qm files
2
# from .ts files and updating .ts files from the sources easier.
3
#
4
# An application which has translations can use this include file as
5
# in the following example for “widgetsgallery”:
6
#
7
# Create a subdirectory “translations” in the source folder of the
8
# application which contains a translations.po file and the .ts
9
# files, for example if the source dir is “libm/demos/widgetsgallery”:
10
#
11
#    libm/demos/widgetsgallery/translations.pro
12
#    libm/demos/widgetsgallery/widgetsgallery_ar.ts
13
#    libm/demos/widgetsgallery/widgetsgallery_de.ts
14
#    libm/demos/widgetsgallery/widgetsgallery_en.ts
15
#    libm/demos/widgetsgallery/widgetsgallery_fi.ts
16
#
17
# The translations.pro file should have contents like this:
18
#
19
#    LANGUAGES = ar de en fi
20
#    CATALOGNAME = widgetsgallery
21
#    SOURCEDIR = $$PWD/..
22
#    TRANSLATIONDIR = $$PWD
23
#    MROOT = ../../..
24
#    include($$MROOT/mconfig.pri)
25
#    include($$MROOT/translations.pri)
26
#
27
# It is better to have an extra translations.pro file in the directory
28
# where the translations are instead of adding the stuff for the translations
29
# to the .pro file of the application (“widgetsgallery.pro”).
30
# It is possible to add similar stuff to update the .qm files
31
# directly to the application profile but the disadvantage is that
32
# changing the .ts files then causes the application to rebuild
33
# (because of qmake limitations).
34
#
35
# Introducing the extra translations/translations.pro file makes it
36
# necessary to add the widgetsgallery/translations directory to the
37
# list of sub-directories in a .pro file higher up in the directory
38
# hierarchy. For example the libm/demos/demos.pro file contains
39
# something like the following:
40
#
41
#    SUBDIRS     =  \
42
#        servicefw \
43
#        widgetsgallery \
44
#        widgetsgallery/translations \
45
#        animatedlayout \
46
#        animatedlayout/translations \
47
#        launcher \
48
#        qtstyleexample
49
#
50
51
# get around lack of sleep on Windows:
52
unix:SLEEP = sleep 1
53
else:SLEEP = ping -n 5 localhost > NUL
54
# null device:
55
unix:NULL = /dev/null
56
else:NULL = NUL
57
58
# var, prepend, append
59
defineReplace(prependAll) {
60
    for(a,$$1):result += $$2$${a}$$3
61
    return($$result)
62
}
63
64
isEmpty(LRELEASE_OPTIONS) {
65
    LRELEASE_OPTIONS = -idbased
66
}
67
isEmpty(LUPDATE_OPTIONS) {
68
    LUPDATE_OPTIONS = -locations absolute -no-ui-lines -no-sort
69
}
70
defineReplace(targetPath) {
71
    return($$replace(1, /, $$QMAKE_DIR_SEP))
72
}
73
LRELEASE = $$targetPath($$[QT_INSTALL_BINS]/lrelease) $$LRELEASE_OPTIONS
74
LUPDATE = $$targetPath($$[QT_INSTALL_BINS]/lupdate) $$LUPDATE_OPTIONS
75
# add “-markuntranslated '!!\ '” if available (needs new Qt 4.6):
76
out = $$system($$LRELEASE -help)
77
# the second parameter of contains can be a regexp!
78
contains(out, .*markuntranslated.*) {
79
    LRELEASE += -markuntranslated '!!\ '
80
}
81
82
TRANSLATIONS = $$prependAll(LANGUAGES, $$TRANSLATIONDIR/$${CATALOGNAME}_,.ts)
83
84
isEqual(TEMPLATE_PREFIX, vc):vcproj=1
85
isEmpty(vcproj) {
86
    QMAKE_LINK = @: IGNORE THIS LINE
87
    OBJECTS_DIR =
88
    win32:CONFIG -= embed_manifest_exe
89
} else {
90
    CONFIG += console
91
    PHONY_DEPS = .
92
    phony_src.input = PHONY_DEPS
93
    phony_src.output = phony.c
94
    phony_src.variable_out = GENERATED_SOURCES
95
    phony_src.commands = echo int main() { return 0; } > phony.c
96
    phony_src.name = CREATE phony.c
97
    phony_src.CONFIG += combine
98
    QMAKE_EXTRA_COMPILERS += phony_src
99
}
100
101
102
!isEqual(DISABLE_QTTRID_ENGINEERING_ENGLISH, "yes") {
103
    ENGINEERING_ENGLISH = $$OUT_PWD/$${CATALOGNAME}.ts
104
    # updating the engineering English .ts file should be done *always*
105
    # because it is fully auto-generated, no manual editing is needed:
106
107
    DUMMY_DEP = $$OUT_PWD/dummy-dependency-this-file-will-never-be-created
108
    updateeets.input = DUMMY_DEP
109
    updateeets.output = $$ENGINEERING_ENGLISH
110
    !isEmpty(vcproj):updateeets.variable_out = GENERATED_SOURCES
111
    updateeets.commands = $$LUPDATE $$SOURCEDIR -ts $$ENGINEERING_ENGLISH
112
    updateeets.name = LUPDATE $$ENGINEERING_ENGLISH
113
    updateeets.CONFIG += no_link target_predeps
114
    QMAKE_EXTRA_COMPILERS += updateeets
115
116
    FORCED_DEP = .
117
    dummy.input = FORCED_DEP
118
    dummy.output = $$DUMMY_DEP
119
    !isEmpty(vcproj):dummy.variable_out = GENERATED_SOURCES
120
    # we do not really create $$DUMMY_DEP here, make does not check the
121
    # output of the build steps, it assumes that the build command either
122
    # fails or that the output is created:
123
    dummy.commands = echo > $$NULL
124
    dummy.CONFIG += no_link target_predeps
125
    QMAKE_EXTRA_COMPILERS += dummy
126
}
127
128
# the stuff below works as well on Linux, but does not work with vcproj
129
# because PRE_TARGETDEPS (just like .CONFIG += target_predeps) does
130
# not work for vcproj output.
131
#
132
# !isEqual(DISABLE_QTTRID_ENGINEERING_ENGLISH, "yes") {
133
#     ENGINEERING_ENGLISH = $$OUT_PWD/$${CATALOGNAME}.ts
134
#     # updating the engineering English .ts file should be done *always*
135
#     # because it is fully auto-generated, no manual editing is needed:
136
#
137
#     updateeets.commands = $$LUPDATE $$SOURCEDIR -ts $$ENGINEERING_ENGLISH
138
#     QMAKE_EXTRA_TARGETS += updateeets
139
#     QMAKE_CLEAN += $$ENGINEERING_ENGLISH
140
#     PRE_TARGETDEPS = updateeets
141
# }
142
143
# other .ts files besides the engineering English one should only be updated
144
# on request, i.e. only when calling “make updatets” manually:
145
updatets.commands = $$LUPDATE $$SOURCEDIR -ts $$TRANSLATIONS
146
updatets.target = updatets
147
QMAKE_EXTRA_TARGETS += updatets
148
149
updateqm.input = TRANSLATIONS
150
!isEqual(DISABLE_QTTRID_ENGINEERING_ENGLISH, "yes") {
151
    updateqm.input += ENGINEERING_ENGLISH
152
}
153
updateqm.output = $$OUT_PWD/${QMAKE_FILE_BASE}.qm
154
updateqm.commands = $$LRELEASE ${QMAKE_FILE_IN} -qm ${QMAKE_FILE_OUT};
155
updateqm.name = LRELEASE ${QMAKE_FILE_IN}
156
updateqm.CONFIG += no_link target_predeps
157
QMAKE_EXTRA_COMPILERS += updateqm
158
159
isEqual(INSTALL_TRANSLATIONS, "no") {
160
    # do not install the .qm files
161
}
162
else {
163
    isEmpty(TRANSLATION_INSTALLDIR) {
164
        TRANSLATION_INSTALLDIR = $${M_TRANSLATION_DIR}
165
    }
166
    qmfiles.files = $$prependAll(LANGUAGES, $$OUT_PWD/$${CATALOGNAME}_,.qm)
167
    !isEqual(DISABLE_QTTRID_ENGINEERING_ENGLISH, "yes") {
168
        qmfiles.files += $$OUT_PWD/$${CATALOGNAME}.qm
169
    }
170
    qmfiles.CONFIG += no_check_exist
171
    qmfiles.path = $${TRANSLATION_INSTALLDIR}
172
173
    INSTALLS += qmfiles
174
}