Start implementing pluralization

This commit is contained in:
dotasek 2022-10-27 17:34:12 -04:00
parent 9e4a19bb61
commit ef2092e500
5 changed files with 30 additions and 10 deletions

View File

@ -1,5 +1,7 @@
package org.hl7.fhir.utilities.i18n;
import com.ibm.icu.text.PluralRules;
import java.text.MessageFormat;
import java.util.Locale;
import java.util.Objects;
@ -14,6 +16,7 @@ public abstract class I18nBase {
private Locale locale;
private ResourceBundle i18nMessages;
private PluralRules pluralRules;
private boolean warnAboutMissingMessages = true;
public Locale getLocale() {
@ -38,6 +41,12 @@ public abstract class I18nBase {
}
}
private void checkPluralRulesAreLoaded() {
if (pluralRules == null) {
setPluralRules(getLocale());
}
}
/**
* Checks the loaded {@link ResourceBundle} to see if the passed in message exists with the current loaded {@link Locale}.
* If no {@link Locale} is currently loaded, it will load the {@link Locale} (default {@link Locale#US} is none is
@ -68,7 +77,11 @@ public abstract class I18nBase {
}
return formatMessageP(theMessage, theMessageArguments);
}
protected String getPluralKey(Integer number, String baseKey) {
return baseKey + "_" + pluralRules.select(number);
}
private String formatMessageP(String theMessage, Object... theMessageArguments) {
String message = theMessage;
if (messageExistsForLocale(theMessage, (theMessageArguments != null && theMessageArguments.length > 0))) {
@ -89,7 +102,9 @@ public abstract class I18nBase {
for (int i = 0; i < theMessageArguments.length; i++) {
args[i+1] = theMessageArguments[i];
}
return formatMessageP(theMessage, args);
checkPluralRulesAreLoaded();
String pluralKey = getPluralKey(plural, theMessage);
return formatMessageP(pluralKey, args);
}
/**
@ -100,6 +115,10 @@ public abstract class I18nBase {
i18nMessages = ResourceBundle.getBundle("Messages", locale);
}
public void setPluralRules(Locale locale) {
pluralRules = PluralRules.forLocale(locale);
}
public boolean isWarnAboutMissingMessages() {
return warnAboutMissingMessages;
}

View File

@ -328,7 +328,6 @@ public class I18nConstants {
public static final String QUESTIONNAIRE_QR_ITEM_STRINGNOOPTIONS = "Questionnaire_QR_Item_StringNoOptions";
public static final String QUESTIONNAIRE_QR_ITEM_TEXT = "Questionnaire_QR_Item_Text";
public static final String QUESTIONNAIRE_QR_ITEM_TIMENOOPTIONS = "Questionnaire_QR_Item_TimeNoOptions";
public static final String QUESTIONNAIRE_QR_ITEM_WRONGTYPE = "Questionnaire_QR_Item_WrongType";
public static final String QUESTIONNAIRE_QR_ITEM_WRONGTYPE_PLURAL = "Questionnaire_QR_Item_WrongType_PLURAL";
public static final String QUESTIONNAIRE_QR_Q_NONE = "Questionnaire_QR_Q_None";
public static final String QUESTIONNAIRE_QR_Q_NOTFOUND = "Questionnaire_QR_Q_NotFound";

View File

@ -99,8 +99,8 @@ Questionnaire_QR_Item_Order = Structural Error: items are out of order
Questionnaire_QR_Item_StringNoOptions = Cannot validate string answer option because no option list is provided
Questionnaire_QR_Item_Text = If text exists, it must match the questionnaire definition for linkId {0}
Questionnaire_QR_Item_TimeNoOptions = Cannot validate time answer option because no option list is provided
Questionnaire_QR_Item_WrongType = Answer value must be of type {0}
Questionnaire_QR_Item_WrongType_PLURAL = Answer value must be one of the {0} types {1}
Questionnaire_QR_Item_WrongType_PLURAL_one = Answer value must be of the type {1}
Questionnaire_QR_Item_WrongType_PLURAL_other = Answer value must be one of the {0} types {1}
Questionnaire_QR_Q_None = No questionnaire is identified, so no validation can be performed against the base questionnaire
Questionnaire_QR_Q_NotFound = The questionnaire ''{0}'' could not be resolved, so no validation can be performed against the base questionnaire
Questionnaire_Q_EnableWhen_After = The target of this enableWhen rule ({0}) comes after the question itself
@ -752,4 +752,4 @@ TYPE_SPECIFIER_NM_ILLEGAL_TYPE = No Type specifier matched, and the underlying t
TYPE_SPECIFIER_NM_ABSTRACT_TYPE = No Type specifier matched, and the underlying type {0} is not abstract
ELEMENT_CANNOT_BE_NULL = The element is not allowed to be 'null'
MULTIPLE_LOGICAL_MODELS_PLURAL={0} Logical Models found in supplied profiles, so unable to parse logical model (can only be one, found {1})
}

View File

@ -93,8 +93,8 @@ Questionnaire_QR_Item_Order=Struktureller Fehler: Elemente in falscher Reihenfol
Questionnaire_QR_Item_StringNoOptions=String answer option kann nicht validiert werden, da keine Optionsliste bereitgestellt wird
Questionnaire_QR_Item_Text=Wenn Text vorhanden ist, muss er mit der Fragebogen-Definition f\u00fcr linkId {0} \u00fcbereinstimmen.
Questionnaire_QR_Item_TimeNoOptions=Kann die time answer option nicht validieren, weil keine Optionsliste zur Verf\u00fcgung steht
Questionnaire_QR_Item_WrongType=Answer value muss vom Typ {0} sein.
Questionnaire_QR_Item_WrongType_PLURAL=Answer value muss einer der Typen {1} sein
Questionnaire_QR_Item_WrongType_PLURAL_one=Answer value muss vom Typ {0} sein.
Questionnaire_QR_Item_WrongType_PLURAL_other=Answer value muss einer der Typen {1} sein
Questionnaire_QR_Q_None=Es konnte kein passendes questionnaire identifiziert werden, so dass keine Validierung gegen den Basisfragebogen durchgef\u00fchrt werden kann.
Questionnaire_QR_Q_NotFound=Der Fragebogen "{0}" konnte nicht gefunden werden, so dass keine Validierung gegen den Basisfragebogen durchgef\u00fchrt werden kann.
Questionnaire_Q_EnableWhen_After=Das Ziel dieser enableWhen-Regel ({0}) kommt nach der Frage selbst
@ -432,3 +432,4 @@ Unable_to_resolve_system__no_value_set=System nicht aufl\u00f6sbar - kein ValueS
This_base_property_must_be_an_Array_not_a_=Diese Basis Property muss ein Array sein, nicht ein {0}
This_property_must_be_an_Array_not_a_=Diese Eigenschaft muss ein Array sein, nicht ein {0}
documentmsg = (document)

View File

@ -94,8 +94,8 @@ Questionnaire_QR_Item_Order = Structuurfout: items staan niet in de juiste volgo
Questionnaire_QR_Item_StringNoOptions = Kan string-antwoord niet valideren omdat er geen optielijst is gespecificeerd
Questionnaire_QR_Item_Text = Als text bestaat, dan moet dit een questionnaire-definitie bevatten voor linkId {0}
Questionnaire_QR_Item_TimeNoOptions = Kan tijd-antwoord niet valideren omdat er geen optielijst is gespecificeerd
Questionnaire_QR_Item_WrongType = Antwoord moet type {0} hebben
Questionnaire_QR_Item_WrongType_PLURAL = Antwoord moet een van de types {1} hebben
Questionnaire_QR_Item_WrongType_PLURAL_one=Antwoord moet type {0} hebben
Questionnaire_QR_Item_WrongType_PLURAL_other=Antwoord moet een van de types {1} hebben
Questionnaire_QR_Q_None = Er is geen questionnaire gedentificeerd, dus validatie tegen de questionnaire is niet mogelijk
Questionnaire_QR_Q_NotFound = De questionnaire ''{0}'' is niet gevonden, dus validatie tegen de questionnaire is niet mogelijk
Questionnaire_Q_EnableWhen_After = Het doel van deze enableWhen regel ({0}) komt pas na deze vraag
@ -654,3 +654,4 @@ BUNDLE_SEARCH_ENTRY_WRONG_RESOURCE_TYPE_OUTCOME = Dit is geen OperationOutcome (
BUNDLE_SEARCH_ENTRY_WRONG_RESOURCE_TYPE_NO_MODE = Dit is geen overeenkomstig resourcetype voor de opgegeven zoekactie (is een search.mode nodig?) ({0} verwacht {1})
BUNDLE_SEARCH_NO_MODE = SearchSet bundles zouden search.mode op de entries moeten hebben
INV_FAILED = Regel {0} mislukt