mirror of
https://github.com/oxen-io/session-android.git
synced 2025-06-09 12:38:33 +00:00
Ensure all support article urls are the correct format and not translatable.
This commit is contained in:
parent
35f4f3f81e
commit
dbb31420af
@ -1935,7 +1935,7 @@
|
|||||||
<string name="KbsSplashFragment__introducing_pins">Introducing PINs</string>
|
<string name="KbsSplashFragment__introducing_pins">Introducing PINs</string>
|
||||||
<string name="KbsSplashFragment__pins_add_another_level_of_security_to_your_account">PINs add another level of security to your account. Create one now.</string>
|
<string name="KbsSplashFragment__pins_add_another_level_of_security_to_your_account">PINs add another level of security to your account. Create one now.</string>
|
||||||
<string name="KbsSplashFragment__learn_more">Learn More</string>
|
<string name="KbsSplashFragment__learn_more">Learn More</string>
|
||||||
<string name="KbsSplashFragment__learn_more_link">https://support.signal.org/hc/en-us/articles/360007059792-Registration-Lock</string>
|
<string name="KbsSplashFragment__learn_more_link" translatable="false">https://support.signal.org/hc/articles/360007059792</string>
|
||||||
<string name="KbsSplashFragment__registration_lock_equals_pin">Registration Lock = PIN</string>
|
<string name="KbsSplashFragment__registration_lock_equals_pin">Registration Lock = PIN</string>
|
||||||
<string name="KbsSplashFragment__your_registration_lock_is_now_called_a_pin">Your Registration Lock is now called a PIN, and it does more. Update it now.</string>
|
<string name="KbsSplashFragment__your_registration_lock_is_now_called_a_pin">Your Registration Lock is now called a PIN, and it does more. Update it now.</string>
|
||||||
<string name="KbsSplashFragment__read_more_about_pins">Read more about PINs.</string>
|
<string name="KbsSplashFragment__read_more_about_pins">Read more about PINs.</string>
|
||||||
@ -1955,7 +1955,7 @@
|
|||||||
<string name="AccountLockedFragment__your_account_has_been_locked_to_protect_your_privacy">Your account has been locked to protect your privacy and security. After %1$d days of inactivity in your account you\'ll be able to re-register this phone number without needing your PIN. All content will be deleted.</string>
|
<string name="AccountLockedFragment__your_account_has_been_locked_to_protect_your_privacy">Your account has been locked to protect your privacy and security. After %1$d days of inactivity in your account you\'ll be able to re-register this phone number without needing your PIN. All content will be deleted.</string>
|
||||||
<string name="AccountLockedFragment__next">Next</string>
|
<string name="AccountLockedFragment__next">Next</string>
|
||||||
<string name="AccountLockedFragment__learn_more">Learn More</string>
|
<string name="AccountLockedFragment__learn_more">Learn More</string>
|
||||||
<string name="AccountLockedFragment__learn_more_url">https://support.signal.org/hc/en-us/articles/360007059792-Registration-Lock</string>
|
<string name="AccountLockedFragment__learn_more_url" translatable="false">https://support.signal.org/hc/articles/360007059792</string>
|
||||||
|
|
||||||
<!-- KbsLockFragment -->
|
<!-- KbsLockFragment -->
|
||||||
<string name="RegistrationLockFragment__enter_your_pin">Enter your PIN</string>
|
<string name="RegistrationLockFragment__enter_your_pin">Enter your PIN</string>
|
||||||
|
@ -0,0 +1,84 @@
|
|||||||
|
package org.thoughtcrime.securesms.l10n;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.w3c.dom.Document;
|
||||||
|
import org.w3c.dom.Node;
|
||||||
|
import org.w3c.dom.NodeList;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
|
|
||||||
|
import static org.hamcrest.CoreMatchers.is;
|
||||||
|
import static org.hamcrest.Matchers.greaterThan;
|
||||||
|
import static org.junit.Assert.assertThat;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
public final class SupportArticleTest {
|
||||||
|
|
||||||
|
private static final File MAIN_STRINGS = new File("src/main/res/values/strings.xml");
|
||||||
|
private static final Pattern SUPPORT_ARTICLE = Pattern.compile(".*:\\/\\/support.signal.org\\/.*articles\\/.*" );
|
||||||
|
private static final Pattern CORRECT_SUPPORT_ARTICLE = Pattern.compile("https:\\/\\/support.signal.org\\/hc\\/articles\\/\\d+");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests that support articles found in strings.xml:
|
||||||
|
* <p>
|
||||||
|
* - Do not have a locale mentioned in the url.
|
||||||
|
* - Only have an article number, i.e. no trailing text.
|
||||||
|
* - Are https.
|
||||||
|
* - Are marked as translatable="false".
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void ensure_format_and_translatable_state_of_all_support_article_urls() throws Exception {
|
||||||
|
assertTrue(MAIN_STRINGS.exists());
|
||||||
|
|
||||||
|
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||||
|
DocumentBuilder builder = factory.newDocumentBuilder();
|
||||||
|
List<String> errors = new LinkedList<>();
|
||||||
|
int seen = 0;
|
||||||
|
|
||||||
|
try (InputStream fileStream = new FileInputStream(MAIN_STRINGS)) {
|
||||||
|
Document doc = builder.parse(fileStream);
|
||||||
|
NodeList strings = doc.getElementsByTagName("string");
|
||||||
|
|
||||||
|
for (int i = 0; i < strings.getLength(); i++) {
|
||||||
|
Node stringNode = strings.item(i);
|
||||||
|
String string = stringNode.getTextContent();
|
||||||
|
String stringName = stringName(stringNode);
|
||||||
|
|
||||||
|
if (SUPPORT_ARTICLE.matcher(string).matches()) {
|
||||||
|
seen++;
|
||||||
|
|
||||||
|
if (!CORRECT_SUPPORT_ARTICLE.matcher(string).matches()) {
|
||||||
|
errors.add(String.format("Article url format is not correct [%s] url: %s", stringName, string));
|
||||||
|
}
|
||||||
|
if (isTranslatable(stringNode)) {
|
||||||
|
errors.add(String.format("Article string is translatable [%s], add translatable=\"false\"", stringName));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
assertThat(seen, greaterThan(0));
|
||||||
|
assertThat(errors, is(Collections.emptyList()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isTranslatable(Node item) {
|
||||||
|
if (item.hasAttributes()) {
|
||||||
|
Node translatableAttribute = item.getAttributes().getNamedItem("translatable");
|
||||||
|
return translatableAttribute == null || !"false".equals(translatableAttribute.getTextContent());
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String stringName(Node item) {
|
||||||
|
return item.getAttributes().getNamedItem("name").getTextContent();
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user