Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional I18n APIs. #12

Draft
wants to merge 11 commits into
base: master
Choose a base branch
from
24 changes: 24 additions & 0 deletions src/main/java/fr/zcraft/zlib/components/i18n/I.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,16 @@ public static String t(String text, Object... parameters)
{
return I18n.translate(null, null, text, null, null, parameters);
}

public static String t(Locale locale, I18nText text, Object... parameters)
{
return I18n.translate(locale, text, parameters);
}

public static String t(I18nText text, Object... parameters)
{
return t(null, text, parameters);
}

/**
* Translates the string with a plural.
Expand Down Expand Up @@ -305,4 +315,18 @@ public static void sendTcn(Player player, String context, String singular, Strin
player.sendMessage(I18n.translate(I18n.getPlayerLocale(player), context, singular, plural, count, parameters));
}

public static I18nText i(String messageId)
{
return i(messageId, null, null, null);
}

public static I18nText i(String messageId, String pluralMessageId, Integer count)
{
return i(messageId, pluralMessageId, count, null);
}

public static I18nText i(String messageId, String pluralMessageId, Integer count, String context)
{
return new I18nText(messageId, pluralMessageId, count, context);
}
}
5 changes: 5 additions & 0 deletions src/main/java/fr/zcraft/zlib/components/i18n/I18n.java
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,11 @@ public static String translate(String context, String messageId, String messageI
return translate(null, context, messageId, messageIdPlural, count, parameters);
}

public static String translate(Locale locale, I18nText text, Object... parameters)
Copy link
Member

@AmauryCarrade AmauryCarrade Jul 18, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Javadoc manquante (pas que là d'ailleurs mais je ne vais pas mettre un commentaire par méthode)

{
return translate(null, text.getContext(), text.getMessageId(), text.getMessageId(), text.getCount(), parameters);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return translate(null, text.getContext(), text.getMessageId(), /* → */ text.getPluralMessageId(), /* ← */ text.getCount(), parameters);

?

}

/**
* Replaces some formatting codes into system codes.
*
Expand Down
84 changes: 84 additions & 0 deletions src/main/java/fr/zcraft/zlib/components/i18n/I18nText.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* Copyright or © or Copr. ZLib contributors (2015 - 2016)
*
* This software is governed by the CeCILL-B license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL-B
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited
* liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL-B license and that you accept its terms.
*/

package fr.zcraft.zlib.components.i18n;

public class I18nText
{
private final String messageId;
private final String pluralMessageId;
private final Integer count;
private final String context;

private Object[] parameters;

public I18nText(String messageId, String pluralMessageId, Integer count, String context)
{
this.messageId = messageId;
this.pluralMessageId = pluralMessageId;
this.count = count;
this.context = context;
}

public I18nText(String messageId)
{
this(messageId, null, null, null);
}

public String getMessageId()
{
return messageId;
}

public String getPluralMessageId()
{
return pluralMessageId;
}

public Integer getCount()
{
return count;
}

public String getContext()
{
return context;
}

public Object[] getParameters()
{
return parameters;
}

public void setParameters(Object[] parameters)
{
this.parameters = parameters;
}
}