/** * Create a new LANGUAGE object from either its short code, its full * name or its ISO code. * @param whatever Short code, full name or ISO code. * @return LANGUAGE */ public static LANGUAGE mapToLanguage(String whatever) { for (LANGUAGE currentLanguage : LANGUAGE.values()) { if (currentLanguage.shortCode.equalsIgnoreCase(whatever) || currentLanguage.fullName.equalsIgnoreCase(whatever) || currentLanguage.isoCode.equalsIgnoreCase(whatever) || currentLanguage.toString().equalsIgnoreCase(whatever)) { return currentLanguage; } if(currentLanguage.aliases != null) { for(String s : currentLanguage.aliases) if(whatever.equalsIgnoreCase(s)) return currentLanguage; } } return null; }
/** * Initialize the Node localization with the node's default language, and * overrides in the working directory. */ public NodeL10n() { this(LANGUAGE.getDefault(), new File(".")); }
new NodeL10n(BaseL10n.LANGUAGE.mapToLanguage(nodeConfig.getString("l10n")), getCfgDir()); } catch (MissingResourceException e) { try { new NodeL10n(BaseL10n.LANGUAGE.mapToLanguage(nodeConfig.getOption("l10n").getDefault()), getCfgDir()); } catch (MissingResourceException e1) { new NodeL10n(BaseL10n.LANGUAGE.mapToLanguage(BaseL10n.LANGUAGE.getDefault().shortCode), getCfgDir());
@Override public String next() { if (state == FallbackState.CURRENT_LANG) { state = FallbackState.FALLBACK_LANG; String value = getString(key, true); if (value != null) { return value; } } if (state == FallbackState.FALLBACK_LANG) { state = FallbackState.KEY; if (getSelectedLanguage() != LANGUAGE.getDefault()) { String value = getFallbackString(key); if (value != null) { return value; } } } if (state == FallbackState.KEY) { state = FallbackState.END; return key; } throw new NoSuchElementException(); }
public void testStrings() throws Exception { for (LANGUAGE lang : LANGUAGE.values()) { BaseL10n l10n = createL10n(lang); SimpleFieldSet fields = l10n.getCurrentLanguageTranslation(); if (fields != null) { for (Iterator<String> itr = fields.keyIterator(); itr.hasNext();) { String key = itr.next(); String value = fields.get(key); try { l10n.attemptParse(value); } catch (L10nParseException e) { fail("Error in "+key+" for "+lang+": "+e.getMessage()); } } } } }
@Override public SimpleFieldSet getFieldSet() { SimpleFieldSet sfs = new SimpleFieldSet(true); // FIXME sfs.putSingle("FCPVersion", "2.0"); sfs.putSingle("Node", "Fred"); sfs.putSingle("Version", Version.getVersionString()); sfs.put("Build", Version.buildNumber()); sfs.putSingle("Revision", Version.cvsRevision()); sfs.put("ExtBuild", NodeStarter.extBuildNumber); sfs.putSingle("ExtRevision", NodeStarter.extRevisionNumber); sfs.put("Testnet", Node.isTestnetEnabled()); sfs.putSingle("CompressionCodecs", Compressor.COMPRESSOR_TYPE.getHelloCompressorDescriptor()); sfs.putSingle("ConnectionIdentifier", id); sfs.putSingle("NodeLanguage", NodeL10n.getBase().getSelectedLanguage().toString()); return sfs; }
public static String[] valuesWithFullNames() { LANGUAGE[] allValues = values(); ArrayList<String> result = new ArrayList<String>(allValues.length); for (int i = 0; i < allValues.length; i++) { // We will return the full names sorted alphabetically. To ensure that the user // notices the special "UNLISTED" language code, we add it to the end of the list // after sorting, so now we skip it. if(allValues[i] != UNLISTED) result.add(allValues[i].fullName); } Collections.sort(result); result.add(UNLISTED.fullName); return result.toArray(new String[result.size()]); }
public BaseL10n(String l10nFilesBasePath, String l10nFilesMask, String l10nOverrideFilesMask) { this(l10nFilesBasePath, l10nFilesMask, l10nOverrideFilesMask, LANGUAGE.getDefault()); }
@Override public void set(String val) throws InvalidConfigValueException { if(val == null || get().equalsIgnoreCase(val)) return; try { NodeL10n.getBase().setLanguage(BaseL10n.LANGUAGE.mapToLanguage(val)); } catch (MissingResourceException e) { throw new InvalidConfigValueException(e.getLocalizedMessage()); } PluginManager.setLanguage(NodeL10n.getBase().getSelectedLanguage()); }
@Override public String[] getPossibleValues() { return BaseL10n.LANGUAGE.valuesWithFullNames(); } }
/** * Load the fallback translation. Synchronized. */ private synchronized void loadFallback() { if (this.fallbackTranslation == null) { this.fallbackTranslation = loadTranslation(LANGUAGE.getDefault()); if(fallbackTranslation == null) fallbackTranslation = new SimpleFieldSet(true); } }