/** * Converts a locale identifier to the internal string value for a language/locale code for this connector. * By default, this simply returns the string of the given LocaleId. * * @param locId * the locale identifier to convert. * @return the internal string code for language/locale code for this connector. */ protected String toInternalCode (LocaleId locId) { return locId.toString(); }
/** * 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; }
public WordCounter (LocaleId locId) { breaker = BreakIterator.getWordInstance(locId.toJavaLocale()); String lng = locId.getLanguage(); replaceApos = ( lng.equals("fr") || lng.equals("it") ); }
/** * 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)); }
/** * 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)); }
/** * Gets a POSIX locale identifier for this LocaleId. * For example: "af-za" returns "af_ZA". * @return the corresponding POSIX locale identifier for this LocaleId. */ public String toPOSIXLocaleId() { //TODO: Make it simpler, and complete it String tmp = getLanguage(); if (getRegion() != null) { tmp += ("_" + getRegion().toUpperCase()); } return tmp; }
if ( srcLoc != null && !srcLoc.equals(LocaleId.EMPTY)) { if ( !srcLoc.sameLanguageAs(src) ) { logger.warn("Discrepancy between expected source ({}) and source in document ({}), Using '{}'", srcLoc.toString(), src, src); srcLoc = LocaleId.fromBCP47(src); srcLoc = LocaleId.fromBCP47(src); writer.create(writerBuffer, srcLoc.toBCP47()); if ( trgLoc != null && !trgLoc.equals(LocaleId.EMPTY)) { if ( !trgLoc.sameLanguageAs(trg) ) { logger.warn("Discrepancy between expected target ({}) and target in document ({}), Using '{}'", trgLoc.toString(), trg, trg); trgLoc = LocaleId.fromBCP47(trg); trgLoc = LocaleId.fromBCP47(trg);
prop = resource.getSourceProperty(name); else if ( locToUse.equals(LocaleId.EMPTY) ) { // Use the resource-level properties prop = resource.getProperty(name); LocaleId locId = LocaleId.fromString(value); if ( locId.sameLanguageAs(inputLoc) ) { value = outputLoc.toString();
LocaleId srcLoc = LocaleId.fromString(parts[1]); if ( !srcLoc.equals(input.getSourceLocale()) ) { logger.warn("The source locale declared in the file ('{}') is not the expected one ('{}')\n{} will be used.", srcLoc.toString(), input.getSourceLocale().toString(), input.getSourceLocale().toString()); trgLoc = LocaleId.fromString(parts[2]); if ( input.getTargetLocale() != null ) { if ( !trgLoc.equals(input.getTargetLocale()) ) { logger.warn("The target locale declared in the file ('{}') is not the expected one ('{}')\n{} will be used.", trgLoc.toString(), input.getTargetLocale().toString(), input.getTargetLocale().toString()); trgLoc = input.getTargetLocale();
String resolvedPath = Util.fillRootDirectoryVariable(params.getTmxPath(), rootDir); resolvedPath = Util.fillInputRootDirectoryVariable(resolvedPath, inputRootDir); resolvedPath = LocaleId.replaceVariables(resolvedPath, sourceLocale, targetLocale); tmx = new TMXWriter(resolvedPath); tmx.writeStartDocument(sourceLocale, targetLocale, 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());
if (item.equals(localeId)) return false; Matcher matcher = pattern.matcher(localeId.toString()); if (matcher.matches()) return false; if (localeId.sameLanguageAs(language)) return false; if (localeId.sameRegionAs(region)) return false; if (localeId.sameUserPartAs(userPart)) return false; if (item.equals(localeId)) return true; Matcher matcher = pattern.matcher(localeId.toString()); if (matcher.matches()) return true; if (localeId.sameLanguageAs(language)) return true; if (localeId.sameRegionAs(region)) return true;
/** * 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); }
@StepParameterMapping(parameterType = StepParameterType.SOURCE_LOCALE) public void setSourceLocale (LocaleId sourceLocale) { this.srcLoc = sourceLocale; srcWordIterator = (RuleBasedBreakIterator) BreakIterator.getWordInstance(ULocale .createCanonical(srcLoc.toString())); RuleBasedBreakIterator.registerInstance(srcWordIterator, srcLoc.toJavaLocale(), BreakIterator.KIND_WORD); }
private void clarifyMarkup(Markup markup) { Nameable nameableMarkupComponent = markup.getNameableMarkupComponent(); if (null != nameableMarkupComponent) { BidirectionalityClarifier bidirectionalityClarifier = new BidirectionalityClarifier( new CreationalParameters( eventFactory, nameableMarkupComponent.getName().getPrefix(), nameableMarkupComponent.getName().getNamespaceURI()), new ClarificationParameters(LocaleId.isBidirectional(targetLocale), LocaleId.hasCharactersAsNumeralSeparators(targetLocale), targetLocale.toString())); bidirectionalityClarifier.clarifyMarkup(markup); } }
/** * 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; }
/** * Indicates if a locale id is null or empty. * @param locale the locale id to examine. * @return true if the given locale id is null or empty, false otherwise. */ static public boolean isNullOrEmpty (LocaleId locale) { return (( locale == null ) || ( locale.equals(LocaleId.EMPTY) )); }
/** * Indicates whether or not the language is considered a "logographic" language per * the GMX-V 2.0 spec. If <code>true</code>, word counts for this language are defined as * (character count / {@link #getCharacterCountFactor(LocaleId)}), unless the character * count factor is <code>-1d</code> in which case word counts are not meaningful for * the language. * * @see web http://www.xtm-intl.com/manuals/gmx-v/GMX-V-2.0.html#LogographicScripts */ public static boolean isLogographicScript(LocaleId locId) { return LOGOGRAPHICSCRIPTS.matcher(locId.toBCP47()).matches(); }
@Override protected String toInternalCode (LocaleId locale) { String code = locale.toBCP47(); String lang = locale.getLanguage(); if ( locale.getRegion() == null ) { // TDA langs have all a region code: Try to add it here. boolean found = false; for ( int i=0; i<LANGSMAP.length; i++ ) { if ( lang.equals(LANGSMAP[i][0]) ) { code = LANGSMAP[i][1]; found = true; break; } } if ( !found ) { // Default: region code is same as lang code: fr-fr code = lang+"-"+lang; } } return code; }
/** * 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; }