Skip to content

Commit

Permalink
language name fix for audio with l_spa (default) in bandidos
Browse files Browse the repository at this point in the history
  • Loading branch information
courville committed May 8, 2024
1 parent 9a8c68c commit ec5991e
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/com/archos/mediacenter/utils/ISO639codes.java
Original file line number Diff line number Diff line change
Expand Up @@ -371,25 +371,25 @@ public static boolean isLanguageInString(String language, String string) {
public static String replaceLanguageCodeInString(String string) {
// treat strings being "l_XYZ" or "l_XY" or "XYZ" or "XY" or "title (l_XYZ)" or "title (l_XY)"
// and replace it with locale language corresponding to XY or XYZ letter code
log.debug("replaceLanguageCodeInString: string=" + string);
log.debug("replaceLanguageCodeInString: input string=" + string);
if (string == null) return "";
String pattern = "(?:^l_([A-Za-z]{2,3}$)|\\(l_([A-Za-z]{2,3})\\)$)"; // 2 or 3 letters code
String pattern = "(?:^l_([A-Za-z]{2,3}\\b)|\\(l_([A-Za-z]{2,3})\\)$)"; // 2 or 3 letters code
String languageCode = "";
Pattern regexPattern = Pattern.compile(pattern);
Matcher matcher = regexPattern.matcher(string);
String result = "";
if (matcher.find()) {
String languageCode1 = matcher.group(1);
String languageCode2 = matcher.group(2);
log.debug("replaceLanguageCodeInString: languageCode1=" + languageCode1 + " languageCode2=" + languageCode2);
if (languageCode1 != null) {
languageCode = languageCode1;
if (languageCode1.equals("und") || languageCode1.equals("Unknown")) return ""; // und = undefined
return capitalizeFirstLetter(string.replaceAll(pattern, ISO639codes.getLanguageNameForLetterCode(languageCode)));
result = capitalizeFirstLetter(string.replaceAll(pattern, ISO639codes.getLanguageNameForLetterCode(languageCode)));
} else if (languageCode2 != null) {
languageCode = languageCode2;
return string.replaceAll(pattern, "(" + ISO639codes.getLanguageNameForLetterCode(languageCode) + ")");
result = string.replaceAll(pattern, "(" + ISO639codes.getLanguageNameForLetterCode(languageCode) + ")");
}
return string; // this never happens?
} else {
// could be that it is a 2|3 letter code alone: treat this case too
pattern = "^[A-Za-z]{2,3}$"; // 2 or 3 letters code
Expand All @@ -398,12 +398,16 @@ public static String replaceLanguageCodeInString(String string) {
if (matcher.find()) {
languageCode = matcher.group();
log.debug("replaceLanguageCodeInString: languageCode=" + languageCode);
if (languageCode.equals("und") || languageCode.equals("Unknown")) return ""; // und = undefined
return capitalizeFirstLetter(string.replaceAll(pattern, ISO639codes.getLanguageNameForLetterCode(languageCode)));
if (languageCode.equals("und") || languageCode.equals("Unknown")) result = ""; // und = undefined
else result = capitalizeFirstLetter(string.replaceAll(pattern, ISO639codes.getLanguageNameForLetterCode(languageCode)));
} else {
log.error("replaceLanguageCodeInString: no languageCode in " + string);
result = string;
}
log.error("replaceLanguageCodeInString: no languageCode in " + string);
return string;
}
log.debug("replaceLanguageCodeInString: input={} -> result={}", string, result);
return result;

}

}

0 comments on commit ec5991e

Please sign in to comment.