Skip to content

Commit

Permalink
Javadoc
Browse files Browse the repository at this point in the history
  • Loading branch information
phlppchrtn committed Jun 11, 2024
1 parent aa59991 commit c59cabf
Showing 1 changed file with 30 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,28 @@
import io.vertigo.core.util.StringUtil;

/**
* Texte pouvant être externalisé dans un fichier de ressources,
* en fonction du paramétrage de l'application.
* Si le libelle n'est pas trouvé, l'affichage est
* A Text that can be externalized in a resource file,
* based on the application's configuration settings.
* If the label is not found, the display is
*
* @author npiedeloup, pchretien
*/
public final class LocaleMessageText implements Serializable {
private static final long serialVersionUID = 4723023230514051954L;
/** Clé du libellé dans le dictionnaire. */
/** Key of the label in the dictionary. */
private final LocaleMessageKey key;
/** Libellé non formatté. */
/** Unformatted label. */
private final String defaultMsg;
/** paramètres permettant de formatter le libellé. */
/** Parameters allowing to format the label. */
private final Serializable[] params;

/**
* Constructor.
* La clé et/ou le message par défaut doit être non null.
* The key and/or default message must be non-null.
*
* @param defaultMsg Message par défaut (non formatté) de la ressource
* @param key Clé de la ressource
* @param params paramètres de la ressource
* @param defaultMsg Default message (unformatted) of the resource
* @param key Key of the resource
* @param params Parameters of the resource
*/
private LocaleMessageText(final String defaultMsg, final LocaleMessageKey key, final Serializable... params) {
Assertion.check()
Expand All @@ -61,9 +61,9 @@ private LocaleMessageText(final String defaultMsg, final LocaleMessageKey key, f
}

/**
* static Builder of a messageText by its key.
* Static Builder of a messageText by its key.
*
* @param key Clé de la ressource
* @param key Key of the resource
* @return the messageText
*/
public static LocaleMessageText of(final LocaleMessageKey key, final Serializable... params) {
Expand All @@ -73,9 +73,9 @@ public static LocaleMessageText of(final LocaleMessageKey key, final Serializabl
}

/**
* static Builder of a messageText by its default message.
* Static Builder of a messageText by its default message.
*
* @param msg Message par défaut (non formatté) de la ressource
* @param msg Default message (unformatted) of the resource
* @return the messageText
*/
public static LocaleMessageText of(final String msg, final Serializable... params) {
Expand All @@ -85,9 +85,9 @@ public static LocaleMessageText of(final String msg, final Serializable... param
}

/**
* static Builder of a messageText by its default message.
* Static Builder of a messageText by its default message.
*
* @param defaultMsg Message par défaut (non formatté) de la ressource
* @param defaultMsg Default message (unformatted) of the resource
* @return the messageText
*/
public static LocaleMessageText ofDefaultMsg(final String defaultMsg, final LocaleMessageKey key, final Serializable... params) {
Expand All @@ -99,40 +99,41 @@ public static LocaleMessageText ofDefaultMsg(final String defaultMsg, final Loca
}

/**
* @return paramètres du message
* @return parameters of the message
*/
private Object[] getParams() {
return params;
}

/**
* Format message with parameters.
* No exception throwed !!
* No exception thrown!!
*
* @return Formatted message, if exists.
*/
public Optional<String> getDisplayOpt() {
Locale locale = null;
String msg = null;
if (key != null) {
//On ne recherche le dictionnaire (géré par localeManager) que si il y a une clé.
// Only search the dictionary (managed by localeManager) if there is a key.
try {
//Il est nécessaire que LocaleManager soit enregistré.
//Si pas d'utilisateur on prend la première langue déclarée.
// It is necessary that LocaleManager is registered.
// If no user is present, the first declared language is taken.
final var localeManager = getLocaleManager();
locale = localeManager.getCurrentLocale();
msg = localeManager.getMessage(key, locale);
} catch (final Exception e) {
//Si pas de locale msg est null et on va récupérer s'il existe le message par défaut.
// If LocaleManager is not registered or generates an exception
// then msg remains null and we retrieve the default message if it exists.
}
}

//Si pas de clé on recherche le libellé par défaut.
// If no key is found, we search for the default message.
if (msg == null) {
msg = defaultMsg;
}
if (msg != null) {
//On passe toujours dans le StringUtil.format pour unifier.
// We always pass through StringUtil.format to unify.
return Optional.of(StringUtil.format(msg, getParams()));
}

Expand All @@ -141,16 +142,16 @@ public Optional<String> getDisplayOpt() {

/**
* Format message with parameters.
* If nothing found, return a "panic message" displaying what is missing.
* No exception throwed !!
* If nothing is found, return a "panic message" displaying what is missing.
* No exception thrown!!
*
* @return Formatted message.
*/
public String getDisplay() {
/*
* Cette méthode doit toujours remonter un message.
* Si LocaleManager n'est pas enregistré ou génère une exception
* alors on se contente de retourner la clé du message.
* This method must always return a message.
* If LocaleManager is not registered or generates an exception
* then we return the key of the message.
*/
return getDisplayOpt().orElseGet(() -> getPanicMessage());
}
Expand Down

0 comments on commit c59cabf

Please sign in to comment.