Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
rhbz842214 - Modify locale naming rules to accept other separator cha…
Browse files Browse the repository at this point in the history
…racters.

Locale names will now use '.' and '@' as separators to find plural forms for locales.
  • Loading branch information
Carlos Munoz committed Jul 24, 2012
1 parent 1b46173 commit 14985aa
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
Expand Up @@ -225,7 +225,6 @@ public boolean isLanguageNameValid()
// Check for plural forms
if( resourceUtils.getPluralForms( localeId, false ) == null )
{
// Have to get the component Id this way as binding won't work on a Page scoped bean.
this.languageNameWarningMessage = messages.get("jsf.language.validation.UnknownPluralForm");
}

Expand Down
Expand Up @@ -1046,8 +1046,16 @@ public String getPluralForms(LocaleId localeId)
*/
public String getPluralForms(LocaleId localeId, boolean useDefault)
{
final char[] alternateSeparators = {'.', '@'};

String javaLocale = localeId.toJavaName().toLowerCase();

// Replace all alternate separators for the "_" (Java) separator.
for( char sep : alternateSeparators )
{
javaLocale = javaLocale.replace(sep, '_');
}

if (pluralForms.containsKey(javaLocale))
{
return pluralForms.getProperty(javaLocale);
Expand Down
@@ -1,6 +1,7 @@
package org.zanata.rest.service;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.MatcherAssert.assertThat;

import java.util.ArrayList;
Expand Down Expand Up @@ -330,4 +331,25 @@ public void readPluralForms()
}
}

@Test
public void pluralFormsAlternateSeparators()
{
ResourceUtils resourceUtils = new ResourceUtils();
resourceUtils.create();

// Plural forms for "es"
String esPluralForm = resourceUtils.getPluralForms( new LocaleId("es") );
assertThat(esPluralForm, notNullValue());

// Alternate forms that should match the "es" plurals
// "es_ES"
assertThat( resourceUtils.getPluralForms( new LocaleId("es-ES") ), is( esPluralForm ) );
// "es.ES"
assertThat( resourceUtils.getPluralForms( new LocaleId("es.ES") ), is( esPluralForm ) );
// "es@ES"
assertThat( resourceUtils.getPluralForms( new LocaleId("es@ES") ), is( esPluralForm ) );
// "es.ES@Latin"
assertThat( resourceUtils.getPluralForms( new LocaleId("es.ES@Latin") ), is( esPluralForm ) );
}

}

0 comments on commit 14985aa

Please sign in to comment.