/** * Converts a list of language codes into {@link LocaleId}s * @param languageCodes the list of codes. * @return the list of {@link LocaleId} objects created. */ public static List<LocaleId> convertToLocaleIds(List<String> languageCodes) { List<LocaleId> locales = new ArrayList<LocaleId>(); for (String languageCode : languageCodes) { locales.add(LocaleId.fromString(languageCode)); } return locales; }
/** * Replaces the locale/language variables in a given input string by their runtime values. * If one of the locale passed is null, its corresponding variables are replaced by an empty string. * @param input the string with the variables. * @param srcLoc the source locale code (can be null). * @param trgLoc the target locale code (can be null). * @return the modified string. */ static public String replaceVariables(String input, String srcLoc, String trgLoc) { return replaceVariables(input, LocaleId.fromString(srcLoc == null ? "" : srcLoc), LocaleId.fromString(trgLoc == null ? "" : trgLoc)); }
/** * Indicates if a given string has the same user part as the one of this LocaleId. * For example: "es-us-x-win" and "en-us@win" returns true, "es-us@mac" and "es-us@ats" return false. * @param langCode the string to compare. * @return true if the region parts of both objects are the same. */ public boolean sameUserPartAs(String langCode) { return sameUserPartAs(LocaleId.fromString(langCode)); }
/** * Gets an LCID for a given language tag. * @param tag the language tag to lookup. * @return the LCID value found. */ public static int getLCID (String tag) { return getLCID(LocaleId.fromString(tag)); }
public LocaleId getTargetLocale () { return LocaleId.fromString(getString(TARGETLOCALE)); }
public void initialize (String srcLang) { this.srcLang = srcLang; counter = new WordCounter(LocaleId.fromString(srcLang)); }
public LocaleId getSourceLocale () { return LocaleId.fromString(getString(SOURCELOCALE)); }
/** * Gets the value of the xml:lang or lang attribute from the current <tuv> element * @return the language value * @throws OkapiBadFilterInputException if xml:Lang or lang is missing */ private LocaleId getXmlLangFromCurTuv(){ String tmp = reader.getAttributeValue(XMLConstants.XML_NS_URI, "lang"); if ( tmp != null ) { return LocaleId.fromString(tmp); } // If xml:lang not found, fall back to lang (old TMX versions) int count = reader.getAttributeCount(); for ( int i=0; i<count; i++ ) { if ( reader.getAttributeLocalName(i).equals("lang")){ return LocaleId.fromString(reader.getAttributeValue(i)); } } throw new OkapiBadFilterInputException("The required xml:lang or lang attribute is missing in <tuv>. The file is not valid TMX."); }
/** * Registers an LCID for a language tag. * @param lcid the LCID value. * @param tag the language tag. */ private static void registerTag(int lcid, String tag) { LCIDDescr descr; descr = tagLookup.get(lcid); if (descr == null) { Logger localLogger = LoggerFactory.getLogger(LCIDUtil.class); // logger.warn(String.format("Unregistered LCID: 0x%04x %s -- %s\n" + // "registerLCID(\"%s\", \"\", 0x%04x);\n", lcid, tag, // LanguageList.getDisplayName(tag), LanguageList.getDisplayName(tag), lcid)); localLogger.warn(String.format("Unregistered LCID: 0x%04x %s\n", lcid, tag)); return; } tag = LocaleId.fromString(tag).toString(); descr.tag = tag; lcidLookup.put(tag, descr); }
/** * Splits up a string of comma-separated substrings representing locale codes into a * string list of {@link LocaleId} objects. * @param input string of comma-separated substrings. * @return a list of {@link LocaleId} objects. */ public static List<LocaleId> stringAsLanguageList (String input) { if ( input == null ) return null; List<LocaleId> res = new ArrayList<LocaleId>(); List<String> list = new ArrayList<String>(); stringAsList(list, input, ","); for ( String lang : list ) { lang = lang.trim(); if ( !Util.isEmpty(lang) ) { res.add(LocaleId.fromString(lang)); } } return res; }
/** * Gets an array of the LocaleId objects for all the Java locales installed on the system. * @return an array of the LocaleId objects for all the available Java locales. */ static public LocaleId[] getAvailableLocales() { ULocale[] jlocales = ULocale.getAvailableLocales(); LocaleId[] locIds = new LocaleId[jlocales.length]; for (int i = 0; i < jlocales.length; i++) { locIds[i] = LocaleId.fromString(jlocales[i].toLanguageTag()); } return locIds; }
LocaleId getLocaleValue(Document doc, TranslationUnitField field) { return LocaleId.fromString(getFieldValue(doc, field.name())); }
/** * Splits a given locale tag (e.g. "fr-ca") into its components. * Use this method when working directly with an {@link LocaleId} object is not desirable. * This method supports only simple ISO codes (not complex BCP-47 tags). * @param locId the locale code to process. * @return an array of two strings: 0=language, 1=region/country (or empty) * @deprecated don't use this. It only "understands" language + region, * but that is just a small part of what BCP 47 supports. */ @Deprecated public static String[] splitLanguageCode(String locId) { final String[] parts = {"", ""}; if ((locId == null) || (locId.length() == 0)) { return parts; } final LocaleId loc = LocaleId.fromString(locId); final String language = loc.getLanguage(); final String region = loc.getRegion(); if (language != null) parts[0] = language; if (region != null) parts[1] = region; return parts; }
srcLoc = LocaleId.fromString(tmp); trgLoc = LocaleId.fromString(tmp);
return false; project.setSourceLocale(LocaleId.fromString(tmp)); return false; project.setTargetLocale(LocaleId.fromString(tmp));
lent = new LangEntry(LocaleId.fromString(lang));
/** * Compares this LocaleId with a given object. * @param arg the object to compare. If the parameter is a string it is normalized * before being compared. * @return 1 if the parameter is null. If the parameter is a LocaleId or * a string, the return is the same as the return of a comparison between * the identifier of this LocaleId and the string representation of the argument. * Otherwise the return is 1; */ public int compareTo(Object arg) { if (arg == null) { return 1; } if (arg instanceof LocaleId) { final String locId1 = toBCP47(); final String locId2 = ((LocaleId) arg).toBCP47(); return locId1.compareTo(locId2); } if (arg instanceof String) { final String locId1 = toBCP47(); final String locId2 = LocaleId.fromString((String) arg).toBCP47(); return locId1.compareTo(locId2); } return 1; }
LocaleId.fromString(edSampleLanguage.getText()), (forceReset ? null : segmenter));
tu.setTargetContent(LocaleId.fromString(this.trgLangCode), new TextFragment(tpe.getTargetNode().getTextContent()));
deScore1to2Prop = new Property("Txt::EDScore", "", false); fmScore1to2Prop = new Property("Txt::FMScore", "", false); targetLocale2Extra = LocaleId.fromString(targetLocale.toString()+params.getTarget2Suffix()); deScore1to3Prop = new Property("Txt::EDScore1to3", "", false); fmScore1to3Prop = new Property("Txt::FMScore1to3", "", false); targetLocale3Extra = LocaleId.fromString(targetLocale.toString()+params.getTarget3Suffix());