Class TranslationResult
If evaluating a reachable expression-fragment predicate or
interpolating its selected/default fragment fails, a handler-produced result reports
TranslationFailureReason.RESOLUTION_FAILURE and exposes the runtime cause. The
default fallback policy
stops at that failure, while
TranslationFallbackPolicy.fallbackOnAnyFailure() may first try another locale. Expression-selected fragments
have required defaults and therefore cannot themselves produce
TranslationFailureReason.NO_MATCHING_ALTERNATIVE.
- Since:
- 3.0.0
- Author:
- Mark Allen
-
Constructor Summary
ConstructorsConstructorDescriptionTranslationResult(@NonNull String key, @NonNull String translation, @NonNull Locale lookupLocale, @Nullable LocaleMatchResult localeMatchResult, @Nullable Locale resolvedLocale, @NonNull List<@NonNull Locale> attemptedLocales, @NonNull TranslationResultStatus status, @Nullable TranslationFailureReason failureReason, @Nullable Throwable cause) Constructs a translation result with locale-negotiation diagnostics.TranslationResult(@NonNull String key, @NonNull String translation, @NonNull Locale lookupLocale, @Nullable Locale resolvedLocale, @NonNull List<@NonNull Locale> attemptedLocales, @NonNull TranslationResultStatus status, @Nullable TranslationFailureReason failureReason, @Nullable Throwable cause) Constructs a translation result. -
Method Summary
Modifier and TypeMethodDescriptionGets the ordered locales actually attempted.getCause()Gets the first runtime resolution cause for a failed lookup.Gets the final lookup failure reason for handler-produced results.getKey()Gets the translation key.Gets strict locale-negotiation diagnostics when available.Gets the locale used to begin per-key locale fallback after any negotiation.Gets the locale that resolved successfully.Gets how the returned string was produced.Gets the returned translation, key, or handler-supplied string.Reports whether negotiation or per-key resolution used a fallback.toString()Generates a diagnostic representation without rendering translation contents or throwable messages.
-
Constructor Details
-
TranslationResult
public TranslationResult(@NonNull String key, @NonNull String translation, @NonNull Locale lookupLocale, @Nullable Locale resolvedLocale, @NonNull List<@NonNull Locale> attemptedLocales, @NonNull TranslationResultStatus status, @Nullable TranslationFailureReason failureReason, @Nullable Throwable cause) Constructs a translation result. This is public so customStringsimplementations can participate in the diagnostic result API.- Parameters:
key- translation key, not nulltranslation- returned string, not nulllookupLocale- locale used to begin per-key locale fallback, not nullresolvedLocale- successfully resolved locale, or null for a failure-handler responseattemptedLocales- ordered locales actually attempted, not nullstatus- result status, not nullfailureReason- final failure reason for a handler response, otherwise nullcause- first runtime resolution cause, including an evaluated expression-fragment or selected/default fragment failure, otherwise null- Throws:
IllegalArgumentException- if any locale is malformed, success and failure state is mixed, a resolution cause and reason disagree, attempted locales contain duplicates, or the resolved locale was not attempted
-
TranslationResult
public TranslationResult(@NonNull String key, @NonNull String translation, @NonNull Locale lookupLocale, @Nullable LocaleMatchResult localeMatchResult, @Nullable Locale resolvedLocale, @NonNull List<@NonNull Locale> attemptedLocales, @NonNull TranslationResultStatus status, @Nullable TranslationFailureReason failureReason, @Nullable Throwable cause) Constructs a translation result with locale-negotiation diagnostics.- Parameters:
key- translation key, not nulltranslation- returned string, not nulllookupLocale- locale used to begin per-key locale fallback, not nulllocaleMatchResult- strict locale-negotiation result, or null when unavailableresolvedLocale- successfully resolved locale, or null for a failure-handler responseattemptedLocales- ordered locales actually attempted, not nullstatus- result status, not nullfailureReason- final failure reason for a handler response, otherwise nullcause- runtime resolution cause, including an evaluated expression-fragment or selected/default fragment failure, otherwise null- Throws:
IllegalArgumentException- if any locale is malformed, success and failure state is mixed, a resolution cause and reason disagree, attempted locales contain duplicates, or the resolved locale was not attempted
-
-
Method Details
-
getKey
-
getTranslation
Gets the returned translation, key, or handler-supplied string.- Returns:
- returned translation, key, or handler-supplied string, not null
-
getLookupLocale
Gets the locale used to begin per-key locale fallback after any negotiation.- Returns:
- locale used to begin per-key locale fallback after any negotiation, not null
-
getLocaleMatchResult
Gets strict locale-negotiation diagnostics when available.- Returns:
- strict locale-negotiation diagnostics when available, otherwise empty, not null
-
getResolvedLocale
Gets the locale that resolved successfully.- Returns:
- locale that resolved successfully, or empty for a failure response, not null
-
getAttemptedLocales
Gets the ordered locales actually attempted.- Returns:
- ordered locales actually attempted, not null
-
getStatus
Gets how the returned string was produced.- Returns:
- how the returned string was produced, not null
-
getFailureReason
Gets the final lookup failure reason for handler-produced results.Evaluated expression-fragment predicate and selected/default fragment failures are
TranslationFailureReason.RESOLUTION_FAILURE; an expression-selected fragment cannot itself produceTranslationFailureReason.NO_MATCHING_ALTERNATIVEbecause it has a required default.- Returns:
- final lookup failure reason for handler-produced results, otherwise empty, not null
-
getCause
-
isFallback
Reports whether negotiation or per-key resolution used a fallback.- Returns:
- whether negotiation produced no match, used CLDR parent, likely-subtag, or primary-language fallback, or per-key resolution used a non-equivalent locale, not null
-
toString
-