aboutsummaryrefslogtreecommitdiffstats
path: root/lint/libs/lint_api
diff options
context:
space:
mode:
authorTor Norbye <tnorbye@google.com>2012-08-03 21:41:58 -0700
committerTor Norbye <tnorbye@google.com>2012-08-06 09:27:55 -0700
commit9a666a7cf24a78455482b79b4fbe4c1eba0481ce (patch)
treef347233490ca4e9e0afe13bb16558c5b99533b01 /lint/libs/lint_api
parent057e5374a3c774555b8c0d8457997b4c368cf732 (diff)
downloadsdk-9a666a7cf24a78455482b79b4fbe4c1eba0481ce.zip
sdk-9a666a7cf24a78455482b79b4fbe4c1eba0481ce.tar.gz
sdk-9a666a7cf24a78455482b79b4fbe4c1eba0481ce.tar.bz2
35875: Lint too strict about translating strings by default.
This changeset updates the issue explanation for the translation detector to explain the translatable=false and donottranslate.xml mechanisms to handle non-translatable strings. It adds a quickfix for missing translation items to set the translatable attribute to false. It also makes lint warn where you're using translatable=false on strings in a locale-folder, as well as when you're translating a string defined as translatable=false in the base folder. And finally it also bumps up the severity of the extra translations issue as justified in issue 35875. Change-Id: I7539464b234b0a4b444bf9f188ce5b819f962430
Diffstat (limited to 'lint/libs/lint_api')
-rw-r--r--lint/libs/lint_api/src/com/android/tools/lint/detector/api/LintUtils.java37
1 files changed, 37 insertions, 0 deletions
diff --git a/lint/libs/lint_api/src/com/android/tools/lint/detector/api/LintUtils.java b/lint/libs/lint_api/src/com/android/tools/lint/detector/api/LintUtils.java
index 85995b1..1d9ba2e 100644
--- a/lint/libs/lint_api/src/com/android/tools/lint/detector/api/LintUtils.java
+++ b/lint/libs/lint_api/src/com/android/tools/lint/detector/api/LintUtils.java
@@ -670,4 +670,41 @@ public class LintUtils {
return hasManifest;
}
+
+ /**
+ * Look up the locale and region from the given parent folder name and
+ * return it as a combined string, such as "en", "en-rUS", etc, or null if
+ * no language is specified.
+ *
+ * @param folderName the folder name
+ * @return the locale+region string or null
+ */
+ @Nullable
+ public static String getLocaleAndRegion(@NonNull String folderName) {
+ if (folderName.equals("values")) { //$NON-NLS-1$
+ return null;
+ }
+
+ String locale = null;
+
+ for (String qualifier : Splitter.on('-').split(folderName)) {
+ int qualifierLength = qualifier.length();
+ if (qualifierLength == 2) {
+ char first = qualifier.charAt(0);
+ char second = qualifier.charAt(1);
+ if (first >= 'a' && first <= 'z' && second >= 'a' && second <= 'z') {
+ locale = qualifier;
+ }
+ } else if (qualifierLength == 3 && qualifier.charAt(0) == 'r' && locale != null) {
+ char first = qualifier.charAt(1);
+ char second = qualifier.charAt(2);
+ if (first >= 'A' && first <= 'Z' && second >= 'A' && second <= 'Z') {
+ return locale + '-' + qualifier;
+ }
+ break;
+ }
+ }
+
+ return locale;
+ }
}