summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Kyle Kienapfel2022-06-24 21:16:34 -0700
committerGravatar Kyle K2022-07-30 01:40:33 -0700
commit7e0afc641c520d85780074ec685fac1d9fc3e215 (patch)
tree8727502b96d1ef046b6dc689a64b0c8e350f424d
parentUpdate bug-report-feature-request.md (diff)
downloadyuzu-7e0afc641c520d85780074ec685fac1d9fc3e215.tar.gz
yuzu-7e0afc641c520d85780074ec685fac1d9fc3e215.tar.xz
yuzu-7e0afc641c520d85780074ec685fac1d9fc3e215.zip
Translate english plurals
Turns out that for Qt to properly handle plurals in English a translation needs to be provided, otherwise the user is left with messages such as "Building: 2 shader(s)" Plurals for other all other languages are handled on transifex. I wrote the README.md to just refer to it as a translation collaboration site just in case we ever switch. These translations being out of date won't pose any technical problems so I believe it is fine to handle them manually on a "best effort" basis. The files are generated into the source directory so that the relative filenames are correct. The generated file is added to .gitignore
Diffstat (limited to '')
-rw-r--r--.gitignore2
-rw-r--r--.reuse/dep53
-rw-r--r--dist/english_plurals/README.md19
-rw-r--r--dist/english_plurals/en.ts67
-rw-r--r--src/yuzu/CMakeLists.txt14
-rw-r--r--src/yuzu/configuration/configure_ui.cpp1
-rw-r--r--src/yuzu/main.cpp5
7 files changed, 103 insertions, 8 deletions
diff --git a/.gitignore b/.gitignore
index 6207765d8..cdf37962a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,7 +7,7 @@ doc-build/
7 7
8# Generated source files 8# Generated source files
9src/common/scm_rev.cpp 9src/common/scm_rev.cpp
10.travis.descriptor.json 10dist/english_plurals/generated_en.ts
11 11
12# Project/editor files 12# Project/editor files
13*.swp 13*.swp
diff --git a/.reuse/dep5 b/.reuse/dep5
index b4ac2ac26..228cc1b59 100644
--- a/.reuse/dep5
+++ b/.reuse/dep5
@@ -2,7 +2,8 @@ Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
2Comment: It is best to use this file to record copyright information about 2Comment: It is best to use this file to record copyright information about
3 generated, binary and third party files 3 generated, binary and third party files
4 4
5Files: dist/icons/controller/*.png 5Files: dist/english_plurals/*
6 dist/icons/controller/*.png
6 dist/icons/overlay/*.png 7 dist/icons/overlay/*.png
7 dist/languages/* 8 dist/languages/*
8 dist/qt_themes/*/icons/index.theme 9 dist/qt_themes/*/icons/index.theme
diff --git a/dist/english_plurals/README.md b/dist/english_plurals/README.md
new file mode 100644
index 000000000..a4954f6a6
--- /dev/null
+++ b/dist/english_plurals/README.md
@@ -0,0 +1,19 @@
1# English Plurals
2
3Qt has "Translation Rules for Plurals", small example
4
5 // Take a source line like
6 tr("Building: %n shader(s)", "", i)
7
8 // i = 1:
9 Building: 1 shader
10 // i = 2:
11 Building: 2 shaders
12
13For yuzu the source language used is English, for all other languages handling of plurals is handled by Qt and the translation collaboration site. Handling plurals in the source language (English) requires special consideration.
14
15With CMake flag GENERATE_QT_TRANSLATION a generated_en.ts file is created from the source. It ignored by git (`.gitignore` in the project root). It is placed in this directory so that the relative refrences with the source code is correct.
16
17Having the plurals look nice isn't critical, and automation to use translation collaboration sites may require specifing the project language as "Pirate English", so this has been done manually.
18
19The en.ts in this directory is taken from a build, edited in Qt Linguist and then committed. As the code is in XML, using the tool is not strictly required.
diff --git a/dist/english_plurals/en.ts b/dist/english_plurals/en.ts
new file mode 100644
index 000000000..172cd4bba
--- /dev/null
+++ b/dist/english_plurals/en.ts
@@ -0,0 +1,67 @@
1<?xml version="1.0" encoding="utf-8"?>
2<!DOCTYPE TS>
3<TS version="2.1" language="en_US" sourcelanguage="en_US">
4<context>
5 <name>GMainWindow</name>
6 <message numerus="yes">
7 <location filename="../../src/yuzu/main.cpp" line="2322"/>
8 <source>%n file(s) remaining</source>
9 <translation>
10 <numerusform>%n file remaining</numerusform>
11 <numerusform>%n files remaining</numerusform>
12 </translation>
13 </message>
14 <message numerus="yes">
15 <location filename="../../src/yuzu/main.cpp" line="2377"/>
16 <source>%n file(s) were newly installed
17</source>
18 <translation>
19 <numerusform>%n file was newly installed
20</numerusform>
21 <numerusform>%n files were newly installed
22</numerusform>
23 </translation>
24 </message>
25 <message numerus="yes">
26 <location filename="../../src/yuzu/main.cpp" line="2380"/>
27 <source>%n file(s) were overwritten
28</source>
29 <translation>
30 <numerusform>%n file was overwritten
31</numerusform>
32 <numerusform>%n were overwritten
33</numerusform>
34 </translation>
35 </message>
36 <message numerus="yes">
37 <location filename="../../src/yuzu/main.cpp" line="2382"/>
38 <source>%n file(s) failed to install
39</source>
40 <translation>
41 <numerusform>%n file failed to install
42</numerusform>
43 <numerusform>%n files failed to install
44</numerusform>
45 </translation>
46 </message>
47 <message numerus="yes">
48 <location filename="../../src/yuzu/main.cpp" line="3264"/>
49 <source>Building: %n shader(s)</source>
50 <translation>
51 <numerusform>Building: %n shader</numerusform>
52 <numerusform>Building: %n shaders</numerusform>
53 </translation>
54 </message>
55</context>
56<context>
57 <name>GameListSearchField</name>
58 <message numerus="yes">
59 <location filename="../../src/yuzu/game_list.cpp" line="87"/>
60 <source>%1 of %n result(s)</source>
61 <translation>
62 <numerusform>%1 of %n result</numerusform>
63 <numerusform>%1 of %n results</numerusform>
64 </translation>
65 </message>
66</context>
67</TS>
diff --git a/src/yuzu/CMakeLists.txt b/src/yuzu/CMakeLists.txt
index f6b389ede..50007338f 100644
--- a/src/yuzu/CMakeLists.txt
+++ b/src/yuzu/CMakeLists.txt
@@ -221,6 +221,9 @@ if (ENABLE_QT_TRANSLATION)
221 # Update source TS file if enabled 221 # Update source TS file if enabled
222 if (GENERATE_QT_TRANSLATION) 222 if (GENERATE_QT_TRANSLATION)
223 get_target_property(SRCS yuzu SOURCES) 223 get_target_property(SRCS yuzu SOURCES)
224 # these calls to qt_create_translation also creates a rule to generate en.qm which conflicts with providing english plurals
225 # so we have to set a OUTPUT_LOCATION so that we don't have multiple rules to generate en.qm
226 set_source_files_properties(${YUZU_QT_LANGUAGES}/en.ts PROPERTIES OUTPUT_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/translations")
224 qt_create_translation(QM_FILES 227 qt_create_translation(QM_FILES
225 ${SRCS} 228 ${SRCS}
226 ${UIS} 229 ${UIS}
@@ -229,7 +232,13 @@ if (ENABLE_QT_TRANSLATION)
229 -source-language en_US 232 -source-language en_US
230 -target-language en_US 233 -target-language en_US
231 ) 234 )
232 add_custom_target(translation ALL DEPENDS ${YUZU_QT_LANGUAGES}/en.ts) 235
236 # Generate plurals into dist/english_plurals/generated_en.ts so it can be used to revise dist/english_plurals/en.ts
237 set(GENERATED_PLURALS_FILE ${PROJECT_SOURCE_DIR}/dist/english_plurals/generated_en.ts)
238 set_source_files_properties(${GENERATED_PLURALS_FILE} PROPERTIES OUTPUT_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/plurals")
239 qt_create_translation(QM_FILES ${SRCS} ${UIS} ${GENERATED_PLURALS_FILE} OPTIONS -pluralonly -source-language en_US -target-language en_US)
240
241 add_custom_target(translation ALL DEPENDS ${YUZU_QT_LANGUAGES}/en.ts ${GENERATED_PLURALS_FILE})
233 endif() 242 endif()
234 243
235 # Find all TS files except en.ts 244 # Find all TS files except en.ts
@@ -239,6 +248,9 @@ if (ENABLE_QT_TRANSLATION)
239 # Compile TS files to QM files 248 # Compile TS files to QM files
240 qt_add_translation(LANGUAGES_QM ${LANGUAGES_TS}) 249 qt_add_translation(LANGUAGES_QM ${LANGUAGES_TS})
241 250
251 # Compile english plurals TS file to en.qm
252 qt_add_translation(LANGUAGES_QM ${PROJECT_SOURCE_DIR}/dist/english_plurals/en.ts)
253
242 # Build a QRC file from the QM file list 254 # Build a QRC file from the QM file list
243 set(LANGUAGES_QRC ${CMAKE_CURRENT_BINARY_DIR}/languages.qrc) 255 set(LANGUAGES_QRC ${CMAKE_CURRENT_BINARY_DIR}/languages.qrc)
244 file(WRITE ${LANGUAGES_QRC} "<RCC><qresource prefix=\"languages\">\n") 256 file(WRITE ${LANGUAGES_QRC} "<RCC><qresource prefix=\"languages\">\n")
diff --git a/src/yuzu/configuration/configure_ui.cpp b/src/yuzu/configuration/configure_ui.cpp
index 2e98ede8e..48f71b53c 100644
--- a/src/yuzu/configuration/configure_ui.cpp
+++ b/src/yuzu/configuration/configure_ui.cpp
@@ -219,6 +219,7 @@ void ConfigureUi::InitializeLanguageComboBox() {
219 for (const auto& lang : languages) { 219 for (const auto& lang : languages) {
220 if (QString::fromLatin1(lang.id) == QStringLiteral("en")) { 220 if (QString::fromLatin1(lang.id) == QStringLiteral("en")) {
221 ui->language_combobox->addItem(lang.name, QStringLiteral("en")); 221 ui->language_combobox->addItem(lang.name, QStringLiteral("en"));
222 language_files.removeOne(QStringLiteral("en.qm"));
222 continue; 223 continue;
223 } 224 }
224 for (int i = 0; i < language_files.size(); ++i) { 225 for (int i = 0; i < language_files.size(); ++i) {
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp
index f8c234082..d03f1ef69 100644
--- a/src/yuzu/main.cpp
+++ b/src/yuzu/main.cpp
@@ -3975,11 +3975,6 @@ void GMainWindow::UpdateUITheme() {
3975} 3975}
3976 3976
3977void GMainWindow::LoadTranslation() { 3977void GMainWindow::LoadTranslation() {
3978 // If the selected language is English, no need to install any translation
3979 if (UISettings::values.language == QStringLiteral("en")) {
3980 return;
3981 }
3982
3983 bool loaded; 3978 bool loaded;
3984 3979
3985 if (UISettings::values.language.isEmpty()) { 3980 if (UISettings::values.language.isEmpty()) {