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

Commit

Permalink
rhbz836092 - Allowing addition of locales for which no plural informa…
Browse files Browse the repository at this point in the history
…tion is found.

A warning will be shown when this occurs but the system won't prevent the addition of the new locale. All other locale validation rules still apply.
  • Loading branch information
Carlos Munoz committed Jun 29, 2012
1 parent 49ce2a7 commit 7b992e7
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ public boolean isLanguageNameValid()

// Cannot use FacesMessages as they are request scoped.
// Cannot use UI binding as they don't work in Page scoped beans
// TODO Use the new (since 1.7) FlashScopeBean

// Check that locale Id is syntactically valid
LocaleId localeId;
Expand All @@ -222,11 +223,10 @@ public boolean isLanguageNameValid()
}

// Check for plural forms
if( resourceUtils.getPluralForms( localeId ) == null )
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.languageNameValidationMessage = messages.get("jsf.language.validation.UnknownPluralForm");
return false;
this.languageNameWarningMessage = messages.get("jsf.language.validation.UnknownPluralForm");
}

// Check for similar already registered languages (warning)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1014,6 +1014,8 @@ private String getSystemVersion()

/**
* Returns the appropriate plural form for a given Locale.
* Returns a default value if there is no plural form information
* for the provided locale.
*/
public String getPluralForms(HLocale locale)
{
Expand All @@ -1022,8 +1024,22 @@ public String getPluralForms(HLocale locale)

/**
* Returns the appropriate plural form for a given Locale Id.
* Returns a default value if there is no plural form information
* for the provided locale id.
*
* @see {@link ResourceUtils#getPluralForms(org.zanata.common.LocaleId, boolean)}
*/
public String getPluralForms(LocaleId localeId)
{
return getPluralForms(localeId, true);
}

/**
* Returns the appropriate plural from for a given locale Id.
*
* @return A default value if useDefault is True. Otherwise, null.
*/
public String getPluralForms(LocaleId localeId, boolean useDefault)
{
String javaLocale = localeId.toJavaName().toLowerCase();

Expand All @@ -1044,8 +1060,14 @@ public String getPluralForms(LocaleId localeId)
}
}

// Not found, return the default
return DEFAULT_PLURAL_FORM;
if( useDefault )
{
return DEFAULT_PLURAL_FORM;
}
else
{
return null;
}
}

public int getNumPlurals(HDocument document, HLocale hLocale)
Expand Down
2 changes: 1 addition & 1 deletion zanata-war/src/main/resources/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ jsf.language.validation.Existing=This language already exists
jsf.language.validation.Invalid=Invalid Language Name
jsf.language.validation.ReplaceUnderscores=Replace them.
jsf.language.validation.Underscores=Underscores should be replaced with dashes.
jsf.language.validation.UnknownPluralForm=Language has no entry in pluralforms.properties
jsf.language.validation.UnknownPluralForm=Warning: No plural information available. Assuming no plurals.
jsf.language.validation.SimilarLocaleFound=Similar languages found:
jsf.language.manager.DisableByDefaultConfirmation=Are you sure you wish to Disable this language by default?
Expand Down

0 comments on commit 7b992e7

Please sign in to comment.