Skip to content

Commit 0cc0237

Browse files
authored
Fix #5357: Remove CDATA from translatable strings. (#5361)
## Explanation Fixes #5357 This PR removes all ``CDATA`` declarations in the translatable ``strings.xml`` file and instead escapes all necessary characters: < and > (& didn't need to be escaped since no strings use that character at the moment). This is needed because Translatewiki doesn't seem to extract the HTML within the CDATA declaration correctly, so it may not be translated (some existing strings were never translated, and per #5274 the latest FAQ changes aren't being processed correctly (leading to empty translation strings being submitted). This PR also introduces a regex check + test to ensure that CDATA isn't used anymore in strings. ## Essential Checklist - [x] The PR title and explanation each start with "Fix #bugnum: " (If this PR fixes part of an issue, prefix the title with "Fix part of #bugnum: ...".) - [x] Any changes to [scripts/assets](https://github.com/oppia/oppia-android/tree/develop/scripts/assets) files have their rationale included in the PR explanation. - [x] The PR follows the [style guide](https://github.com/oppia/oppia-android/wiki/Coding-style-guide). - [x] The PR does not contain any unnecessary code changes from Android Studio ([reference](https://github.com/oppia/oppia-android/wiki/Guidance-on-submitting-a-PR#undo-unnecessary-changes)). - [x] The PR is made from a branch that's **not** called "develop" and is up-to-date with "develop". - [x] The PR is **assigned** to the appropriate reviewers ([reference](https://github.com/oppia/oppia-android/wiki/Guidance-on-submitting-a-PR#clarification-regarding-assignees-and-reviewers-section)). ## For UI-specific PRs only See video for a demonstration on all of the affected strings still rendering correctly (as far as I can tell) after this change: https://github.com/oppia/oppia-android/assets/12983742/b1102d28-d3a5-4266-969c-d7d84f8d5d38
1 parent b763b6a commit 0cc0237

File tree

3 files changed

+45
-16
lines changed

3 files changed

+45
-16
lines changed

app/src/main/res/values/strings.xml

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -545,11 +545,11 @@
545545
<!-- Privacy Policy -->
546546
<string name="policy_activity_title">Policy Page</string>
547547
<string name="privacy_policy_title">Privacy Policy</string>
548-
<string name="privacy_policy_web_link"><![CDATA[Please visit <a href="https://www.oppia.org/privacy-policy">this page</a> for the latest version of this privacy policy.]]></string>
548+
<string name="privacy_policy_web_link">Please visit &lt;a href="https://www.oppia.org/privacy-policy"&gt;this page&lt;/a&gt; for the latest version of this privacy policy.</string>
549549
<!-- Terms of Service -->
550550
<string name="terms_of_service_title">Terms of Service</string>
551-
<string name="agree_to_terms"><![CDATA[By using %s, you agree to our <br> <oppia-noninteractive-policy link="tos">Terms of Service</oppia-noninteractive-policy> and <oppia-noninteractive-policy link="privacy">Privacy Policy</oppia-noninteractive-policy>.]]></string>
552-
<string name="terms_of_service_web_link"><![CDATA[Please visit <a href="https://www.oppia.org/terms">this page</a> for the latest version of these terms.]]></string>
551+
<string name="agree_to_terms">By using %s, you agree to our &lt;br&gt; &lt;oppia-noninteractive-policy link="tos"&gt;Terms of Service&lt;/oppia-noninteractive-policy&gt; and &lt;oppia-noninteractive-policy link="privacy"&gt;Privacy Policy&lt;/oppia-noninteractive-policy&gt;.</string>
552+
<string name="terms_of_service_web_link">Please visit &lt;a href="https://www.oppia.org/terms"&gt;this page&lt;/a&gt; for the latest version of these terms.</string>
553553
<!-- Frequently asked questions & generic app help. -->
554554
<string name="faq_question_whats_oppia">What is %s?</string>
555555
<string name="faq_question_whos_an_admin">Who is an Administrator?</string>
@@ -565,19 +565,19 @@
565565
<string name="faq_question_update_os">How do I update my Android OS?</string>
566566
<string name="faq_question_cant_find_question">I can\'t find my question here. What now?</string>
567567

568-
<string name="faq_answer_whats_oppia"><![CDATA[<p>%1$s <i>"O-pee-yah"</i> (Finnish) - "to learn"</p><p><br></p><p>%1$s\'s mission is to help anyone learn anything they want in an effective and enjoyable way.</p><p><br></p><p>By creating a set of free, high-quality, demonstrably effective lessons with the help of educators from around the world, %1$s aims to provide students with quality education — regardless of where they are or what traditional resources they have access to.</p><p><br></p><p>As a student, you can begin your learning adventure by browsing the topics listed on the Home Page!</p>]]></string>
569-
<string name="faq_answer_whos_an_admin"><![CDATA[<p>An Administrator is the main user that manages profiles and settings for every profile on their account. They are most likely your parent, teacher, or guardian that created this profile for you. </p><p><br></p><p>Administrators have the ability to manage profiles, assign PINs, and change other settings under their account. Depending on your profile, Administrator permissions may be required for certain features such as changing your PIN, and more. </p><p><br></p><p>To see who your Administrator is, go to the Profile Chooser. The first profile listed and has "Administrator" written under their name is the Administrator. </p>]]></string>
570-
<string name="faq_answer_create_profile"><![CDATA[<p>If it is your first time creating a profile and you do not have a PIN:<ol><li>From the Profile Chooser, tap on <strong>Set up Multiple Profiles</strong>.</li><li>Create a PIN and <strong>Save</strong>.</li><li>Fill in all fields for the profile.<ol><li>(Optional) Upload a photo.</li><li>Enter a name.</li><li>(Optional) Assign a 3-digit PIN.</li></ol></li><li>Tap <strong>Create</strong>. This profile is added to your Profile Chooser!</li></ol></p><p> If you have created a profile before and have a PIN:<ol><li>From the Profile Chooser, tap on <strong>Add Profile</strong>. </li><li>Enter your PIN and tap <strong>Submit</strong>. </li><li>Fill in all fields for the profile.<ol><li> (Optional) Upload a photo. </li><li> Enter a name. </li><li> (Optional) Assign a 3-digit PIN. </li></ol></li><li>Tap <strong>Create</strong>. This profile is added to your Profile Chooser!</li></ol></p><br><p>Note: Only the <u>Administrator</u> is able to manage profiles.</p>]]></string>
571-
<string name="faq_answer_app_language"><![CDATA[<p>The %s app currently supports English, Brazilian Portuguese, Arabic, Swahili and Nigerian Pidgin. Choose one of these languages in the menu, under Options. To request the app in your language, please contact us at <strong>[email protected]<strong>.</p>]]></string>
572-
<string name="faq_answer_bug_reporting"><![CDATA[<p><ol><li>From your %s app home screen, tap the menu in the top left corner.</li><li>Tap <strong>Share feedback</strong>.</li><li>Follow the instructions to report the bug or share feedback.</li></p>]]></string>
573-
<string name="faq_answer_math_lessons"><![CDATA[<p>%1$ss mission is to help learners gain necessary life skills. Math is an essential skill in everyday life. %1$s will be offering new lessons on science and other subjects soon!</p>]]></string>
574-
<string name="faq_answer_more_lessons"><![CDATA[<p>Yes, %s will be offering new lessons on science and other subjects soon. Please check back for updates!</p>]]></string>
575-
<string name="faq_answer_exploration_player"><![CDATA[<p>If the Exploration Player is not loading</p><p><br></p><p>Check to see if the app is up to date:</p><p><ul><li> Go to the Play Store and make sure the app is updated to its latest version </li></ul><p><br></p><p>Check your internet connection:</p><ul><li> If your internet connection is slow, try re-connecting to your Wi-Fi network or connecting to a different network. </li></ul><p>Ask the Administrator to check their device and internet connection:</p><ul><li> Get the Administrator to troubleshoot using the steps above </li></ul><p>Let us know if you still have issues with loading:</p><ul><li> Report a problem by contacting us at [email protected]. </li></ul>]]></string>
576-
<string name="faq_answer_audio_not_playing"><![CDATA[<p>If your audio is not playing</p><p><br></p><p>Check to see if the app is up to date:</p><ul><li> Go to the Play Store and make sure the app is updated to its latest version </li></ul><p><br></p><p>Check your internet connection:</p><ul><li> If your internet connection is slow, try re-connecting to your Wi-Fi network or connecting to a different network. Slow internet may cause the audio to load irregularly, making it difficult to play. </li></ul><p><br></p><p>Ask the Administrator to check their device and internet connection:</p><ul><li> Get the Administrator to troubleshoot using the steps above</li></ul><p><br></p><p>Let us know if you still have issues with loading:</p><ul><li> Report a problem by contacting us at [email protected]. </li></ul>]]></string>
577-
<string name="faq_answer_delete_profile"><![CDATA[<p>Once a profile is deleted:</p><ol><li>The profile cannot be recovered. </li><li> Profile information such as name, photos, and progress will be permanently deleted. </li></ol><p>To delete a profile (excluding the <u>Administrator\'s</u>):</p><ol><li> From the Administrator\'s Home Page, tap on the menu button on the top left. </li><li>Tap on <strong>Administrator Controls</strong>. </li><li>Tap on <strong>Edit Profiles</strong>. </li><li>Tap on the Profile you would like to delete. </li><li>At the bottom of the screen, tap <strong>Profile Deletion</strong>. </li><li>Tap <strong>Delete</strong> to confirm deletion. </li></ol><p><br></p><p>Note: Only the <u>Administrator</u> is able to manage profiles.</p>]]></string>
578-
<string name="faq_answer_update_app"><![CDATA[<p><ol><li>Open the Google Play Store app.</li><li>Search for the %s app.</li><li>Tap Update.</p>]]></string>
579-
<string name="faq_answer_update_os"><![CDATA[<p><ol><li>Tap your phone\'s Settings app.</li><li>Tap System updates.</li><li>Tap System updates and follow the instructions to update your Android operating system.</p>]]></string>
580-
<string name="faq_answer_cant_find_question"><![CDATA[<p>If you cannot find your question or would like to report a bug, contact us at <strong>[email protected].</strong></p>]]></string>
568+
<string name="faq_answer_whats_oppia">&lt;p&gt;%1$s &lt;i&gt;"O-pee-yah"&lt;/i&gt; (Finnish) - "to learn"&lt;/p&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p&gt;%1$s\'s mission is to help anyone learn anything they want in an effective and enjoyable way.&lt;/p&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p&gt;By creating a set of free, high-quality, demonstrably effective lessons with the help of educators from around the world, %1$s aims to provide students with quality education — regardless of where they are or what traditional resources they have access to.&lt;/p&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p&gt;As a student, you can begin your learning adventure by browsing the topics listed on the Home Page!&lt;/p&gt;</string>
569+
<string name="faq_answer_whos_an_admin">&lt;p&gt;An Administrator is the main user that manages profiles and settings for every profile on their account. They are most likely your parent, teacher, or guardian that created this profile for you. &lt;/p&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p&gt;Administrators have the ability to manage profiles, assign PINs, and change other settings under their account. Depending on your profile, Administrator permissions may be required for certain features such as changing your PIN, and more. &lt;/p&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p&gt;To see who your Administrator is, go to the Profile Chooser. The first profile listed and has "Administrator" written under their name is the Administrator. &lt;/p&gt;</string>
570+
<string name="faq_answer_create_profile">&lt;p&gt;If it is your first time creating a profile and you do not have a PIN:&lt;ol&gt;&lt;li&gt;From the Profile Chooser, tap on &lt;strong&gt;Set up Multiple Profiles&lt;/strong&gt;.&lt;/li&gt;&lt;li&gt;Create a PIN and &lt;strong&gt;Save&lt;/strong&gt;.&lt;/li&gt;&lt;li&gt;Fill in all fields for the profile.&lt;ol&gt;&lt;li&gt;(Optional) Upload a photo.&lt;/li&gt;&lt;li&gt;Enter a name.&lt;/li&gt;&lt;li&gt;(Optional) Assign a 3-digit PIN.&lt;/li&gt;&lt;/ol&gt;&lt;/li&gt;&lt;li&gt;Tap &lt;strong&gt;Create&lt;/strong&gt;. This profile is added to your Profile Chooser!&lt;/li&gt;&lt;/ol&gt;&lt;/p&gt;&lt;p&gt; If you have created a profile before and have a PIN:&lt;ol&gt;&lt;li&gt;From the Profile Chooser, tap on &lt;strong&gt;Add Profile&lt;/strong&gt;. &lt;/li&gt;&lt;li&gt;Enter your PIN and tap &lt;strong&gt;Submit&lt;/strong&gt;. &lt;/li&gt;&lt;li&gt;Fill in all fields for the profile.&lt;ol&gt;&lt;li&gt; (Optional) Upload a photo. &lt;/li&gt;&lt;li&gt; Enter a name. &lt;/li&gt;&lt;li&gt; (Optional) Assign a 3-digit PIN. &lt;/li&gt;&lt;/ol&gt;&lt;/li&gt;&lt;li&gt;Tap &lt;strong&gt;Create&lt;/strong&gt;. This profile is added to your Profile Chooser!&lt;/li&gt;&lt;/ol&gt;&lt;/p&gt;&lt;br&gt;&lt;p&gt;Note: Only the &lt;u&gt;Administrator&lt;/u&gt; is able to manage profiles.&lt;/p&gt;</string>
571+
<string name="faq_answer_app_language">&lt;p&gt;The %s app currently supports English, Brazilian Portuguese, Arabic, Swahili and Nigerian Pidgin. Choose one of these languages in the menu, under Options. To request the app in your language, please contact us at &lt;strong&gt;[email protected]&lt;strong&gt;.&lt;/p&gt;</string>
572+
<string name="faq_answer_bug_reporting">&lt;p&gt;&lt;ol&gt;&lt;li&gt;From your %s app home screen, tap the menu in the top left corner.&lt;/li&gt;&lt;li&gt;Tap &lt;strong&gt;Share feedback&lt;/strong&gt;.&lt;/li&gt;&lt;li&gt;Follow the instructions to report the bug or share feedback.&lt;/li&gt;&lt;/p&gt;</string>
573+
<string name="faq_answer_math_lessons">&lt;p&gt;%1$s\'s mission is to help learners gain necessary life skills. Math is an essential skill in everyday life. %1$s will be offering new lessons on science and other subjects soon!&lt;/p&gt;</string>
574+
<string name="faq_answer_more_lessons">&lt;p&gt;Yes, %s will be offering new lessons on science and other subjects soon. Please check back for updates!&lt;/p&gt;</string>
575+
<string name="faq_answer_exploration_player">&lt;p&gt;If the Exploration Player is not loading&lt;/p&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p&gt;Check to see if the app is up to date:&lt;/p&gt;&lt;p&gt;&lt;ul&gt;&lt;li&gt; Go to the Play Store and make sure the app is updated to its latest version &lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p&gt;Check your internet connection:&lt;/p&gt;&lt;ul&gt;&lt;li&gt; If your internet connection is slow, try re-connecting to your Wi-Fi network or connecting to a different network. &lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Ask the Administrator to check their device and internet connection:&lt;/p&gt;&lt;ul&gt;&lt;li&gt; Get the Administrator to troubleshoot using the steps above &lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Let us know if you still have issues with loading:&lt;/p&gt;&lt;ul&gt;&lt;li&gt; Report a problem by contacting us at [email protected]. &lt;/li&gt;&lt;/ul&gt;</string>
576+
<string name="faq_answer_audio_not_playing">&lt;p&gt;If your audio is not playing&lt;/p&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p&gt;Check to see if the app is up to date:&lt;/p&gt;&lt;ul&gt;&lt;li&gt; Go to the Play Store and make sure the app is updated to its latest version &lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p&gt;Check your internet connection:&lt;/p&gt;&lt;ul&gt;&lt;li&gt; If your internet connection is slow, try re-connecting to your Wi-Fi network or connecting to a different network. Slow internet may cause the audio to load irregularly, making it difficult to play. &lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p&gt;Ask the Administrator to check their device and internet connection:&lt;/p&gt;&lt;ul&gt;&lt;li&gt; Get the Administrator to troubleshoot using the steps above&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p&gt;Let us know if you still have issues with loading:&lt;/p&gt;&lt;ul&gt;&lt;li&gt; Report a problem by contacting us at [email protected]. &lt;/li&gt;&lt;/ul&gt;</string>
577+
<string name="faq_answer_delete_profile">&lt;p&gt;Once a profile is deleted:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;The profile cannot be recovered. &lt;/li&gt;&lt;li&gt; Profile information such as name, photos, and progress will be permanently deleted. &lt;/li&gt;&lt;/ol&gt;&lt;p&gt;To delete a profile (excluding the &lt;u&gt;Administrator\'s&lt;/u&gt;):&lt;/p&gt;&lt;ol&gt;&lt;li&gt; From the Administrator\'s Home Page, tap on the menu button on the top left. &lt;/li&gt;&lt;li&gt;Tap on &lt;strong&gt;Administrator Controls&lt;/strong&gt;. &lt;/li&gt;&lt;li&gt;Tap on &lt;strong&gt;Edit Profiles&lt;/strong&gt;. &lt;/li&gt;&lt;li&gt;Tap on the Profile you would like to delete. &lt;/li&gt;&lt;li&gt;At the bottom of the screen, tap &lt;strong&gt;Profile Deletion&lt;/strong&gt;. &lt;/li&gt;&lt;li&gt;Tap &lt;strong&gt;Delete&lt;/strong&gt; to confirm deletion. &lt;/li&gt;&lt;/ol&gt;&lt;p&gt;&lt;br&gt;&lt;/p&gt;&lt;p&gt;Note: Only the &lt;u&gt;Administrator&lt;/u&gt; is able to manage profiles.&lt;/p&gt;</string>
578+
<string name="faq_answer_update_app">&lt;p&gt;&lt;ol&gt;&lt;li&gt;Open the Google Play Store app.&lt;/li&gt;&lt;li&gt;Search for the %s app.&lt;/li&gt;&lt;li&gt;Tap Update.&lt;/p&gt;</string>
579+
<string name="faq_answer_update_os">&lt;p&gt;&lt;ol&gt;&lt;li&gt;Tap your phone\'s Settings app.&lt;/li&gt;&lt;li&gt;Tap System updates.&lt;/li&gt;&lt;li&gt;Tap System updates and follow the instructions to update your Android operating system.&lt;/p&gt;</string>
580+
<string name="faq_answer_cant_find_question">&lt;p&gt;If you cannot find your question or would like to report a bug, contact us at &lt;strong&gt;[email protected].&lt;/strong&gt;&lt;/p&gt;</string>
581581

582582
<string name="profile_edit_fragment_test_activity_label">Profile Edit Fragment Test Activity</string>
583583
<string name="administrator_controls_fragment_test_activity_label">Administrator Controls Fragment Test Activity</string>

scripts/assets/file_content_validation_checks.textproto

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ file_content_checks {
107107
prohibited_content_regex: "translatable=\"false\""
108108
failure_message: "Untranslatable strings should go in untranslated_strings.xml, instead."
109109
}
110+
file_content_checks {
111+
file_path_regex: "app/src/main/res/values/strings\\.xml"
112+
prohibited_content_regex: "CDATA"
113+
failure_message: "CDATA isn't handled by Translatewiki correctly. Use escaped HTML, instead."
114+
}
110115
file_content_checks {
111116
file_path_regex: ".+?\\.xml"
112117
prohibited_content_regex: "<string name=\"[^\"]+\">"

scripts/src/javatests/org/oppia/android/scripts/regex/RegexPatternValidationCheckTest.kt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,8 @@ class RegexPatternValidationCheckTest {
221221
private val referenceComputeIfAbsent =
222222
"computeIfAbsent won't desugar and requires Java 8 support (SDK 24+). Suggest using an atomic" +
223223
" Kotlin-specific solution, instead."
224+
private val cdataShouldNotBeUsed =
225+
"CDATA isn't handled by Translatewiki correctly. Use escaped HTML, instead."
224226
private val wikiReferenceNote =
225227
"Refer to https://github.com/oppia/oppia-android/wiki/Static-Analysis-Checks" +
226228
"#regexpatternvalidation-check for more details on how to fix this."
@@ -2753,6 +2755,28 @@ class RegexPatternValidationCheckTest {
27532755
)
27542756
}
27552757

2758+
@Test
2759+
fun testFileContent_includesCdataContentInStringsXml_fileContentIsNotCorrect() {
2760+
val prohibitedContent =
2761+
"""
2762+
<string name="test"><![CDATA[<p>Some nested HTML.</p>]]></string>
2763+
""".trimIndent()
2764+
tempFolder.newFolder("testfiles", "app", "src", "main", "res", "values")
2765+
val stringFilePath = "app/src/main/res/values/strings.xml"
2766+
tempFolder.newFile("testfiles/$stringFilePath").writeText(prohibitedContent)
2767+
2768+
val exception = assertThrows<Exception>() { runScript() }
2769+
2770+
assertThat(exception).hasMessageThat().contains(REGEX_CHECK_FAILED_OUTPUT_INDICATOR)
2771+
assertThat(outContent.toString().trim())
2772+
.isEqualTo(
2773+
"""
2774+
$stringFilePath:1: $cdataShouldNotBeUsed
2775+
$wikiReferenceNote
2776+
""".trimIndent()
2777+
)
2778+
}
2779+
27562780
/** Runs the regex_pattern_validation_check. */
27572781
private fun runScript() {
27582782
main(File(tempFolder.root, "testfiles").absolutePath)

0 commit comments

Comments
 (0)