📄 locale.java
字号:
* String[] params = new String[]{ "Peter", "Jordan" };
* String translation = Locale . get( "titles.boxing", params );
* <pre>
* @return the translation, e.g. "Peter vs Jordan" or "Peter gegen Jordan"
* @throws NullPointerException when the given parameters are null or if one of the given parameters is null.
*/
//#ifdef false
//# public static final String get( String key, String[] parameters ) {
//#else
public static final String get( int keyId, String[] parameters ) {
//#endif
//#ifdef false
//# short keyId = 0;
//#endif
//#ifdef polish.i18n.useDynamicTranslations
//# if ( !isLoaded ) {
//# initialize();
//# if (isLoadError) {
//# return "";
//# }
//# }
//#endif
// Reshuffle the parameters:
// CHECK: There could be more or less parameters than expected, e.g.
// "hello {2}, you are a {0}"???
// --> some parameters can be ignored
final short[] reorder = multipleParameterOrders[ keyId ];
final String[] reorderedParameters;
if (reorder != null) {
reorderedParameters = new String[ reorder.length ];
for (int i = 0; i < reorderedParameters.length; i++) {
reorderedParameters[i] = parameters[ reorder[i] ];
}
} else {
reorderedParameters = parameters;
}
// Now merge the value with the reordered parameters:
final String[] valueChunks = multipleParameterTranslations[ keyId ];
final StringBuffer result = new StringBuffer();
for (int i = 0; i < reorderedParameters.length; i++) {
String value = valueChunks[i];
result.append( value )
.append( reorderedParameters[ i ]);
}
for (int i = reorderedParameters.length; i < valueChunks.length; i++) {
result.append( valueChunks[i] );
}
// return result:
return result.toString();
}
/**
* Formats the given date to the current locale's format.
* This method just calls the formatDate-method with a new Date instance.
*
* @param time the time in milliseconds after 1.1.1970 GMT.
* @return the locale specific date representation.
* @throws NullPointerException when the date is null
* @see #formatDate(Date)
*/
public static String formatDate( long time ) {
return formatDate( new Date( time ) );
}
/**
* Formats the given date to the current locale's format.
* This method just calls the formatDate-method with a new Calendar instance.
*
* @param date the date
* @return the locale specific date representation.
* @throws NullPointerException when the date is null
* @see #formatDate(Calendar)
*/
public static String formatDate( Date date ) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
return formatDate( calendar );
}
/**
* Formats the given calendar to the current locale's format.
*
* @param calendar the calendar which holds the date
* @return the locale specific date representation.
* @throws NullPointerException when the calendar is null
*/
public static String formatDate( Calendar calendar ) {
StringBuffer buffer = new StringBuffer(10);
formatDate( calendar, buffer );
return buffer.toString();
}
/**
* Formats the given calendar to the current locale's format.
* Use this method for best efficiency.
*
* @param calendar the calendar which holds the date
* @param buffer a StringBuffer, should be at least 10 characters big
* @throws NullPointerException when the calendar is null
*/
public static void formatDate( Calendar calendar, StringBuffer buffer ) {
int year = calendar.get(Calendar.YEAR);
int month = calendar.get( Calendar.MONTH );
int day = calendar.get( Calendar.DAY_OF_MONTH );
//TODO rob set DateFormat variable in TranslationManager
//#if polish.DateFormat == mdy
if (month < 9) {
buffer.append('0');
}
buffer.append( ++month )
//#if polish.DateFormatSeparator:defined
.append("-");
//#else
//# .append("-");
//#endif
if (day < 10) {
buffer.append( '0' );
}
buffer.append( day )
//#if polish.DateFormatSeparator:defined
.append("-");
//#else
//# .append("-");
//#endif
buffer.append( year );
//#elif polish.DateFormat == dmy
//# if (day < 10) {
//# buffer.append( '0' );
//# }
//# buffer.append( day )
//#if polish.DateFormatSeparator:defined
//#= .append("${polish.DateFormatSeparator}");
//#else
//# .append("-");
//#endif
//# if (month < 9) {
//# buffer.append('0');
//# }
//# buffer.append( ++month )
//#if polish.DateFormatSeparator:defined
//#= .append("${polish.DateFormatSeparator}");
//#else
//# .append("-");
//#endif
//# buffer.append( year );
//#else
//# // default to YMD
//# buffer.append( year )
//#if polish.DateFormatSeparator:defined
//#= .append("${polish.DateFormatSeparator}");
//#else
//# .append("-");
//#endif
//# if (month < 9) {
//# buffer.append('0');
//# }
//# buffer.append( ++month )
//#if polish.DateFormatSeparator:defined
//#= .append("${polish.DateFormatSeparator}");
//#else
//# .append("-");
//#endif
//# if (day < 10) {
//# buffer.append( '0' );
//# }
//# buffer.append( day );
//#endif
}
//#ifdef polish.i18n.useDynamicTranslations
//# public static void loadTranslations( String url )
//# throws IOException
//# {
//#debug
//# System.out.println("loading translations from " + url );
//# InputStream is = url.getClass().getResourceAsStream( url );
//# if (is == null) {
//# //System.out.println("!!!!!Cannot find: " + url );
//# throw new IOException();
//# }
//# loadTranslations( new DataInputStream( is ) );
//# }
//#endif
//#ifdef polish.i18n.useDynamicTranslations
//# public static void loadTranslations( DataInputStream in )
//# throws IOException
//# {
//# // read plain translations without any parameters:
//# int numberOfPlainTranslations = in.readInt();
//# String[] plainTs = new String[ numberOfPlainTranslations ];
//# //System.out.println("Loading " + numberOfPlainTranslations + " translations...");
//# for (int i = 0; i < numberOfPlainTranslations; i++) {
//# plainTs[i] = in.readUTF();
//# //System.out.println(plainTs[i]);
//# }
//# plainTranslations = plainTs;
//#
//# // read single parameter translations:
//# int numberOfSingleParameterTranslations = in.readInt();
//# String[] singleParamsTsStart = new String[ numberOfSingleParameterTranslations ];
//# String[] singleParamsTsEnd = new String[ numberOfSingleParameterTranslations ];
//# for (int i = 0; i < numberOfSingleParameterTranslations; i++) {
//# singleParamsTsStart[i] = in.readUTF();
//# singleParamsTsEnd[i] = in.readUTF();
//# }
//# singleParameterTranslationsStart = singleParamsTsStart;
//# singleParameterTranslationsEnd = singleParamsTsEnd;
//#
//# // read translations with several parameters:
//# int numberOfMultipleParametersTranslations = in.readInt();
//# String[][] translationChunks = new String[ numberOfMultipleParametersTranslations ][];
//# short[][] orders = new short[ numberOfMultipleParametersTranslations ][];
//# for (int i = 0; i < numberOfMultipleParametersTranslations; i++) {
//# int numberOfChunks = in.readUnsignedByte();
//# String[] chunkValues = new String[ numberOfChunks ];
//# for (int j = 0; j < numberOfChunks; j++) {
//# chunkValues[j] = in.readUTF();
//# }
//# short[] chunkOrders = new short[ numberOfChunks - 1 ];
//# for (int j = 0; j < numberOfChunks-1; j++) {
//# chunkOrders[j] = (short) in.readUnsignedByte();
//# }
//# translationChunks[i] = chunkValues;
//# orders[i] = chunkOrders;
//# }
//# multipleParameterOrders = orders;
//# multipleParameterTranslations = translationChunks;
//#
//# // now load language name etc, but only when no other language has been loaded before,
//# // because otherwise the default locae settings are intialized anyhow:
//# if (isLoaded) {
//# LANGUAGE = in.readUTF();
//# DISPLAY_LANGUAGE = in.readUTF();
//# MINUS_SIGN = in.readChar();
//# ZERO_DIGIT = in.readChar();
//# DECIMAL_SEPARATOR = in.readChar();
//# MONETARY_DECIMAL_SEPARATOR = in.readChar();
//# GROUPING_SEPARATOR = in.readChar();
//# PERCENT = in.readChar();
//# PERMILL = in.readChar();
//# INFINITY = in.readUTF();
//# String country = in.readUTF();
//# if (country.length() > 0) {
//# COUNTRY = country;
//# DISPLAY_COUNTRY = in.readUTF();
//# CURRENCY_SYMBOL = in.readUTF();
//# CURRENCY_CODE = in.readUTF();
//# } else {
//# COUNTRY = null;
//# DISPLAY_COUNTRY = null;
//# CURRENCY_SYMBOL = null;
//# CURRENCY_CODE = null;
//# }
//# }
//# isLoaded = true;
//# isLoadError = false;
//# }
//#endif
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -