mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-11-16 00:12:51 +00:00
(svn r8906) -Feature: translation dependant formatting of dates.
This commit is contained in:
parent
8df0b8a685
commit
34154aa89e
@ -3137,4 +3137,9 @@ STR_MEASURE_AREA :{BLACK}Area: {N
|
|||||||
STR_MEASURE_LENGTH_HEIGHTDIFF :{BLACK}Length: {NUM}{}Height difference: {NUM} m
|
STR_MEASURE_LENGTH_HEIGHTDIFF :{BLACK}Length: {NUM}{}Height difference: {NUM} m
|
||||||
STR_MEASURE_AREA_HEIGHTDIFF :{BLACK}Area: {NUM} x {NUM}{}Height difference: {NUM} m
|
STR_MEASURE_AREA_HEIGHTDIFF :{BLACK}Area: {NUM} x {NUM}{}Height difference: {NUM} m
|
||||||
|
|
||||||
|
############ Date formatting
|
||||||
|
STR_DATE_TINY :{STRING}-{STRING}-{NUM}
|
||||||
|
STR_DATE_SHORT :{STRING} {NUM}
|
||||||
|
STR_DATE_LONG :{STRING} {STRING} {NUM}
|
||||||
|
|
||||||
########
|
########
|
||||||
|
@ -179,9 +179,17 @@ char *InlineString(char *buf, StringID string)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// This function takes a C-string and allocates a temporary string ID.
|
/**
|
||||||
// The duration of the bound string is valid only until the next GetString,
|
* This function takes a C-string and allocates a temporary string ID.
|
||||||
// so be careful.
|
* The StringID of the bound string is valid until BindCString is called
|
||||||
|
* another NUM_BOUND_STRINGS times. So be careful when using it.
|
||||||
|
*
|
||||||
|
* @note formatting a DATE_TINY calls BindCString twice, thus reduces the
|
||||||
|
* amount of 'user' bound strings by 2.
|
||||||
|
* @todo rewrite the BindCString system to make the limit flexible and
|
||||||
|
* non-round-robin. For example by using smart pointers that free
|
||||||
|
* the allocated StringID when they go out-of-scope/are freed.
|
||||||
|
*/
|
||||||
StringID BindCString(const char *str)
|
StringID BindCString(const char *str)
|
||||||
{
|
{
|
||||||
int idx = (++_bind_index) & (NUM_BOUND_STRINGS - 1);
|
int idx = (++_bind_index) & (NUM_BOUND_STRINGS - 1);
|
||||||
@ -285,40 +293,34 @@ static char *FormatNoCommaNumber(char *buff, int32 number, const char* last)
|
|||||||
static char *FormatYmdString(char *buff, Date date, const char* last)
|
static char *FormatYmdString(char *buff, Date date, const char* last)
|
||||||
{
|
{
|
||||||
YearMonthDay ymd;
|
YearMonthDay ymd;
|
||||||
|
|
||||||
ConvertDateToYMD(date, &ymd);
|
ConvertDateToYMD(date, &ymd);
|
||||||
|
|
||||||
buff = strecpy(buff, GetStringPtr(ymd.day + STR_01AC_1ST - 1), last);
|
int32 args[3] = { ymd.day + STR_01AC_1ST - 1, STR_0162_JAN + ymd.month, ymd.year };
|
||||||
buff = strecpy(buff, " ", last);
|
return FormatString(buff, GetStringPtr(STR_DATE_LONG), args, 0, last);
|
||||||
buff = strecpy(buff, GetStringPtr(STR_0162_JAN + ymd.month), last);
|
|
||||||
buff = strecpy(buff, " ", last);
|
|
||||||
|
|
||||||
return FormatNoCommaNumber(buff, ymd.year, last);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *FormatMonthAndYear(char *buff, Date date, const char* last)
|
static char *FormatMonthAndYear(char *buff, Date date, const char* last)
|
||||||
{
|
{
|
||||||
YearMonthDay ymd;
|
YearMonthDay ymd;
|
||||||
|
|
||||||
ConvertDateToYMD(date, &ymd);
|
ConvertDateToYMD(date, &ymd);
|
||||||
|
|
||||||
buff = strecpy(buff, GetStringPtr(STR_MONTH_JAN + ymd.month), last);
|
int32 args[2] = { STR_MONTH_JAN + ymd.month, ymd.year };
|
||||||
buff = strecpy(buff, " ", last);
|
return FormatString(buff, GetStringPtr(STR_DATE_SHORT), args, 0, last);
|
||||||
|
|
||||||
return FormatNoCommaNumber(buff, ymd.year, last);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *FormatTinyDate(char *buff, Date date, const char* last)
|
static char *FormatTinyDate(char *buff, Date date, const char* last)
|
||||||
{
|
{
|
||||||
YearMonthDay ymd;
|
YearMonthDay ymd;
|
||||||
|
|
||||||
ConvertDateToYMD(date, &ymd);
|
ConvertDateToYMD(date, &ymd);
|
||||||
buff += snprintf(
|
|
||||||
buff, last - buff + 1,
|
|
||||||
" %02i-%02i-%04i", ymd.day, ymd.month + 1, ymd.year
|
|
||||||
);
|
|
||||||
|
|
||||||
return buff;
|
char day[3];
|
||||||
|
char month[3];
|
||||||
|
/* We want to zero-pad the days and months */
|
||||||
|
snprintf(day, lengthof(day), "%02i", ymd.day);
|
||||||
|
snprintf(month, lengthof(month), "%02i", ymd.month + 1);
|
||||||
|
|
||||||
|
int32 args[3] = { BindCString(day), BindCString(month), ymd.year };
|
||||||
|
return FormatString(buff, GetStringPtr(STR_DATE_TINY), args, 0, last);
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *FormatGenericCurrency(char *buff, const CurrencySpec *spec, int64 number, bool compact, const char* last)
|
static char *FormatGenericCurrency(char *buff, const CurrencySpec *spec, int64 number, bool compact, const char* last)
|
||||||
|
Loading…
Reference in New Issue
Block a user