From cefe2e9ef49fff5cc5b0566a642dff4e3237ebae Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Thu, 22 Sep 2022 17:03:45 +0200 Subject: [PATCH 1/8] Add a rule to Danger to check that translation files are not modified by developers. --- docs/danger.md | 1 + tools/danger/dangerfile.js | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/docs/danger.md b/docs/danger.md index afa3555469..34baa62e9e 100644 --- a/docs/danger.md +++ b/docs/danger.md @@ -28,6 +28,7 @@ Here are the checks that Danger does so far: - PR with change on layout should include screenshot in the description - PR which adds png file warn about the usage of vector drawables - non draft PR should have a reviewer +- files containing translations are not modified by developers ### Quality check diff --git a/tools/danger/dangerfile.js b/tools/danger/dangerfile.js index c7db52fa19..6314ec8f68 100644 --- a/tools/danger/dangerfile.js +++ b/tools/danger/dangerfile.js @@ -118,3 +118,10 @@ if (hasPngs) { if (github.requested_reviewers.users.length == 0 && !pr.draft) { warn("Please add a reviewer to your PR.") } + +// Check that translations have not been modified by developers +if (user != "RiotTranslateBot") { + if (editedFiles.some(file => file.endsWith("strings.xml") && !file.endsWith("values/strings.xml"))) { + fail("Some translation files have been edited. Only user `RiotTranslateBot` (i.e. translations coming from Weblate) is allowed to do that.\nPlease read more about translations management [in the doc](https://github.com/vector-im/element-android/blob/develop/CONTRIBUTING.md#internationalisation).") + } +} From a7856db218db6c24fb186383a364259db522f092 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Thu, 22 Sep 2022 17:10:46 +0200 Subject: [PATCH 2/8] Add a section about renaming id of String resource --- CONTRIBUTING.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 52ccf47e6a..e01e1affe8 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -120,7 +120,7 @@ You should consider adding Unit tests with your PR, and also integration tests ( Translations are handled using an external tool: [Weblate](https://translate.element.io/projects/element-android/) -As a general rule, please never edit or add or remove translations to the project in a Pull Request. It can lead to merge conflict if the translations are also modified in Weblate side. +**As a general rule, please never edit or add or remove translations to the project in a Pull Request**. It can lead to merge conflict if the translations are also modified in Weblate side. Pull Request containing change(s) on the translation files cannot be merged. #### Adding new string @@ -150,6 +150,17 @@ And add `tools:ignore="UnusedResources"` to the string, to let lint ignore that The string will be removed during the next sync with Weblate. +#### Renaming string ids + +This is possible to rename ids of the String resources, but since translation files cannot be edited, add TODO in the main strings.xml file above the strings you want to rename. + +```xml + +Hello Matrix world! +``` + +The string id(s) will be renamed during the next Weblate sync. + ### Accessibility Please consider accessibility as an important point. As a minimum requirement, in layout XML files please use attributes such as `android:contentDescription` and `android:importantForAccessibility`, and test with a screen reader if it's working well. You can add new string resources, dedicated to accessibility, in this case, please prefix theirs id with `a11y_`. From 729eba750ba5f5faf0241627dd8e018dfcfd12f1 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Thu, 22 Sep 2022 17:19:57 +0200 Subject: [PATCH 3/8] Add link to the file values/strings.xml, and fix typo in the path. --- CONTRIBUTING.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e01e1affe8..11f6a93dd1 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -124,11 +124,11 @@ Translations are handled using an external tool: [Weblate](https://translate.ele #### Adding new string -When adding new string resources, please only add new entries in the file `value/strings.xml`. Translations will be added later by the community of translators using Weblate. +When adding new string resources, please only add new entries in the file `values/strings.xml` ([this file](./library/ui-strings/src/main/res/values/strings.xml)). Translations will be added later by the community of translators using Weblate. -The file `value/strings.xml` must only contain American English (U. S. English) values, as this is the default language of the Android operating system. So for instance, please use "color" instead of "colour". Element Android will still use the language set on the system by the user, like any other Android applications which provide translations. The system language can be any other English language variants, or any other languages. Note that this is also possible to override the system language using the Element Android in-app language settings. +The file `values/strings.xml` must only contain American English (U. S. English) values, as this is the default language of the Android operating system. So for instance, please use "color" instead of "colour". Element Android will still use the language set on the system by the user, like any other Android applications which provide translations. The system language can be any other English language variants, or any other languages. Note that this is also possible to override the system language using the Element Android in-app language settings. -New strings can be added anywhere in the file `value/strings.xml`, not necessarily at the end of the file. Generally, it's even better to add the new strings in some dedicated section per feature, and not at the end of the file, to avoid merge conflict between 2 PR adding strings at the end of the same file. +New strings can be added anywhere in the file `values/strings.xml`, not necessarily at the end of the file. Generally, it's even better to add the new strings in some dedicated section per feature, and not at the end of the file, to avoid merge conflict between 2 PR adding strings at the end of the same file. Do not hesitate to use plurals when appropriate. From 97c3623f89af7fece9674c410eb3af8ab1b7cbea Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Thu, 22 Sep 2022 17:15:13 +0200 Subject: [PATCH 4/8] Add a note for plurals --- CONTRIBUTING.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 11f6a93dd1..c3df2b7101 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -130,7 +130,11 @@ The file `values/strings.xml` must only contain American English (U. S. English) New strings can be added anywhere in the file `values/strings.xml`, not necessarily at the end of the file. Generally, it's even better to add the new strings in some dedicated section per feature, and not at the end of the file, to avoid merge conflict between 2 PR adding strings at the end of the same file. -Do not hesitate to use plurals when appropriate. +##### Plurals + +Please use `plurals` resources when appropriate, and note that some languages have specific rules for `plurals`, so even if the string will always be at the plural form for English, please always create a `plurals` resource. + +Specific plural forms can be found [here](https://unicode-org.github.io/cldr-staging/charts/37/supplemental/language_plural_rules.html). #### Editing existing strings From 6e2ce10f655a16532c57ca464744e282c2c43e24 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Thu, 22 Sep 2022 17:22:17 +0200 Subject: [PATCH 5/8] Add a note for string reordering --- CONTRIBUTING.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c3df2b7101..8f193c4b72 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -165,6 +165,12 @@ This is possible to rename ids of the String resources, but since translation fi The string id(s) will be renamed during the next Weblate sync. +#### Reordering strings + +To group strings per feature, or for any other reasons, it is possible to reorder string resources, but only in the [main strings.xml file](./library/ui-strings/src/main/res/values/strings.xml). ). We do not mind about ordering in the translation files, and anyway this is forbidden to edit manually the translation files. + +It is also possible to add empty lines between string resources, and to add XML comments. Please note that the XML comment just above a String resource will also appear on Weblate and be visible to the translators. + ### Accessibility Please consider accessibility as an important point. As a minimum requirement, in layout XML files please use attributes such as `android:contentDescription` and `android:importantForAccessibility`, and test with a screen reader if it's working well. You can add new string resources, dedicated to accessibility, in this case, please prefix theirs id with `a11y_`. From c56f33a9398c37db74cf5ba84975f27ce58431c8 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Thu, 22 Sep 2022 17:36:08 +0200 Subject: [PATCH 6/8] Add changelog --- changelog.d/7211.misc | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/7211.misc diff --git a/changelog.d/7211.misc b/changelog.d/7211.misc new file mode 100644 index 0000000000..44abd3d59d --- /dev/null +++ b/changelog.d/7211.misc @@ -0,0 +1 @@ + CI: Prevent modification of translations by developer. From a07761dedb25a73085cc13159e6378077ee5a6c7 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Thu, 22 Sep 2022 17:48:38 +0200 Subject: [PATCH 7/8] Fix issue with knit. --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8f193c4b72..b71e697636 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -159,7 +159,7 @@ The string will be removed during the next sync with Weblate. This is possible to rename ids of the String resources, but since translation files cannot be edited, add TODO in the main strings.xml file above the strings you want to rename. ```xml - + Hello Matrix world! ``` From a5ab942097cbf462b56e99e5457cccc8a61d4d4b Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Thu, 22 Sep 2022 17:52:52 +0200 Subject: [PATCH 8/8] Add TOC to CONTRIBUTING.md --- CONTRIBUTING.md | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b71e697636..6e3c784dac 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,10 +1,42 @@ -# Contributing code to Matrix +# Contributing to Element Android + + + +* [Contributing code to Matrix](#contributing-code-to-matrix) +* [Android Studio settings](#android-studio-settings) + * [Template](#template) +* [Compilation](#compilation) +* [I want to help translating Element](#i-want-to-help-translating-element) +* [I want to submit a PR to fix an issue](#i-want-to-submit-a-pr-to-fix-an-issue) + * [Kotlin](#kotlin) + * [Changelog](#changelog) + * [Code quality](#code-quality) + * [Internal tool](#internal-tool) + * [ktlint](#ktlint) + * [lint](#lint) + * [Unit tests](#unit-tests) + * [Tests](#tests) + * [Internationalisation](#internationalisation) + * [Adding new string](#adding-new-string) + * [Plurals](#plurals) + * [Editing existing strings](#editing-existing-strings) + * [Removing existing strings](#removing-existing-strings) + * [Renaming string ids](#renaming-string-ids) + * [Reordering strings](#reordering-strings) + * [Accessibility](#accessibility) + * [Layout](#layout) + * [Authors](#authors) +* [Thanks](#thanks) + + + +## Contributing code to Matrix Please read https://github.com/matrix-org/synapse/blob/master/CONTRIBUTING.md Element Android support can be found in this room: [![Element Android Matrix room #element-android:matrix.org](https://img.shields.io/matrix/element-android:matrix.org.svg?label=%23element-android:matrix.org&logo=matrix&server_fqdn=matrix.org)](https://matrix.to/#/#element-android:matrix.org). -# Specific rules for Matrix Android projects +The rest of the document contains specific rules for Matrix Android projects ## Android Studio settings