model/src/main/java/eu/internetofus/common/model/ValidateContext.java
/**
   * Verify a field value is {@code null} or a valid locale.
   *
   * @param fieldName name of the checking field.
   * @param value     to verify.
   * @param promise   to notify of any error.
   *
   * @return the normalized locale value.
   */
Verify a field value is  null or a valid locale.
@param fieldName name of the checking field.
@param value     to verify.
@param promise   to notify of any error.

@return the normalized locale value.
Verify a field value is null or a valid locale . @param fieldName name of the checking field . @param value to verify . @param promise to notify of any error . @return the normalized locale value .
default String validateNullableLocaleField(final String fieldName, final String value, final Promise<Void> promise) {
    if (value != null) {
      final var trimmedValue = value.trim();
      if (trimmedValue.length() > 0) {
        try {
          LocaleUtils.toLocale(trimmedValue);
          return trimmedValue;
        } catch (final IllegalArgumentException badLocale) {
          promise.tryFail(new ValidationErrorException(this.fieldErrorCode(fieldName), badLocale));
          return value;
        }
      }
    }
    return null;
  }
default String validateNullableLocaleField ( final String fieldName , final String value , final Promise < Void > promise ) { if ( value != null ) { final var trimmedValue = value . trim ( ) ; if ( trimmedValue . length ( ) > 0 ) { try { LocaleUtils . toLocale ( trimmedValue ) ; return trimmedValue ; } catch ( final IllegalArgumentException badLocale ) { promise . tryFail ( new ValidationErrorException ( this . fieldErrorCode ( fieldName ) , badLocale ) ) ; return value ; } } } return null ; }
Verify a field value is {@code null} or a valid locale.
Verify a field value is { @code null } or a valid locale .