📄 sfllang.c
字号:
/* ----------------------------------------------------------------<Prolog>-
Name: sfllang.c
Title: Multilingual number/date/time support
Package: Standard Function Library (SFL)
Written: 1997/06/04 iMatix SFL project team <sfl@imatix.com>
Revised: 1999/01/02
Copyright: Copyright (c) 1996-2000 iMatix Corporation
License: This is free software; you can redistribute it and/or modify
it under the terms of the SFL License Agreement as provided
in the file LICENSE.TXT. This software is distributed in
the hope that it will be useful, but without any warranty.
TDL: - Abstract accents; provide function to translate any marked-up
string into either accented characters or portable equivalents.
Use a coding like /Ra for a-ring.
- Translate day names into other languages.
- Use US English too?
- Provide certification function.
------------------------------------------------------------------</Prolog>-*/
#include "prelude.h" /* Universal header file */
#include "sflstr.h" /* String functions */
#include "sfldate.h" /* Date functions */
#include "sfllist.h" /* Memory-allocation functions */
#include "sflmem.h" /* Memory-allocation functions */
#include "sfllang.h" /* Function prototypes */
static char
*language_str [] = {
"--",
"DA", "DE", "EN", "ES", "FB", "FR",
"IS", "IT", "NL", "NO", "PO", "SV"
};
static char
*DA_units [] = {
"nul", "en", "to", "tre", "fire", "fem", "seks", "syv", "otte",
"ni", "ti", "elve", "tolv", "tretten", "fjorten", "femten",
"seksten", "sytten", "atten", "nitten"
},
*DE_units [] = {
"null", "ein", "zwei", "drei", "vier", "f乶f", "sechs", "sieben",
"acht", "neun", "zehn", "elf", "zw/Uolf", "dreizehn", "vierzehn",
"f/Uunfzehn", "sechzehn", "siebzehn", "achtzehn", "neunzehn"
},
*EN_units [] = {
"zero", "one", "two", "three", "four", "five", "six", "seven",
"eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen",
"fifteen", "sixteen", "seventeen", "eighteen", "nineteen"
},
*ES_units [] = {
"zero", "uno", "dos", "tres", "cuatro", "cinco", "seis", "siete",
"ocho", "nueve", "diez", "once", "doce", "trece", "catorce", "quince",
"dieciseis", "diecisiete", "dieciocho", "diecinueve"
},
*FR_units [] = {
"zero", "un", "deux", "trois", "quatre", "cinq", "six", "sept",
"huit", "neuf", "dix", "onze", "douze", "treize", "quatorze",
"quinze", "seize", "dix-sept", "dix-huit", "dix-neuf"
},
*IS_units [] = {
"null", "einn", "tweir", "thrir", "fjorir", "fimm", "sex", "sj/Uo",
"atta", "niu", "tiu", "ellefu", "tolf", "threttan", "fjortan",
"fimtan", "sextan", "seytjan", "atjan", "nitjan"
},
*IT_units [] = {
"zero", "uno", "due", "tre", "quattro", "cinque", "sei", "sette",
"otto", "nove", "dieci", "undici", "dodici", "tredici", "quatrodici",
"quindici", "sedici", "diciassette", "diciotto", "dicianove"
},
*NL_units [] = {
"nul", "een", "twee", "drie", "vier", "vijf", "zes", "zeven", "acht",
"negen", "tien", "elf", "twaalf", "dertien", "veertien", "vijftien",
"zestien", "zeventien", "achttien", "negentien"
},
*NO_units [] = {
"null", "en", "to", "tre", "fire", "fem", "seks", "syv", "/Ratte",
"ni", "ti", "elleve", "tolv", "tretten", "fjorten", "femten",
"seksten", "sytten", "atten", "nitten"
},
*PO_units [] = {
"zero", "um", "dois", "tres", "quatro", "cinco", "seis", "sete",
"oito", "nove", "dez", "onze", "doze", "treze", "catorze",
"quinze", "dezasseis", "dezassete", "dezoito", "dezanove"
},
*SV_units [] = {
"noll", "en", "tv/Ra", "tre", "fyra", "fem", "sex", "sju", "/Ratta",
"nio", "tio", "elva", "tolv", "tretton", "fjorton", "femton",
"sexton", "sjutton", "atton", "nitton"
};
static char
*DA_tens [] = {
"ti", "tyve", "tredive", "fyrre", "halvtreds",
"treds", "halvfjerds", "firs", "halvfems"
},
*DE_tens [] = {
"zehn", "zwanzig", "drei/Bsig", "vierzig", "f/Uunfzig",
"sechzig", "siebzig", "achtzig", "neunzig"
},
*EN_tens [] = {
"ten", "twenty", "thirty", "forty", "fifty",
"sixty", "seventy", "eighty", "ninety"
},
*ES_tens [] = {
"diez", "veinti", "treinta", "cuarenta", "cincuenta",
"sesenta", "setenta", "ochenta", "noventa"
},
*FB_tens [] = {
"dix", "vingt", "trente", "quarante", "cinquante",
"soixante", "septante", "quatre-vingt", "nonante"
},
*FR_tens [] = {
"dix", "vingt", "trente", "quarante", "cinquante",
"soixante", "soixante", "quatre-vingt", "quatre-vingt"
},
*IS_tens [] = {
"tiu", "tuttugu", "thrjatiu", "fj/Uorutiu", "fumtiu",
"sextiu", "sj/Uotiu", "attatiu", "niutiu"
},
*IT_tens [] = {
"dieci", "venti", "trenta", "quaranta", "cinquanta",
"sessanta", "settanta", "ottanta", "novanta"
},
*NL_tens [] = {
"tien", "twintig", "dertig", "veertig", "vijftig",
"zestig", "zeventig", "tachtig", "negentig"
},
*NO_tens [] = {
"ti", "tyve", "tredve", "f/Sorti", "femti",
"seksti", "sytti", "/Ratti", "nitti"
},
*PO_tens [] = {
"dez", "vinte", "trinta", "quarenta", "cinquenta",
"sessenta", "setenta", "oitenta", "noventa"
},
*SV_tens [] = {
"tio", "tjugo", "trettio", "fyrtio", "femtio",
"sextio", "sjuttio", "/Rattio", "nittio"
};
static char
*DA_months [] = {
"januar", "februar", "marts", "april", "maj", "juni",
"juli", "august", "september", "oktober", "november", "december"
},
*DE_months [] = {
"Januar", "Februar", "Marsch", "April", "Mai", "Juni",
"Juli", "August", "September", "Oktober", "November", "Dezember"
},
*EN_months [] = {
"January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"
},
*ES_months [] = {
"enero", "febrero", "marzo", "abril", "mayo", "junio",
"julio", "agosto", "setiembre", "octubre", "noviembre", "diciembre"
},
*FR_months [] = {
"janvier", "fevrier", "mars", "avril", "mai", "juin",
"juillet", "ao/Cut", "septembre", "octobre", "novembre", "decembre"
},
*IS_months [] = {
"januar", "februar", "marz", "april", "mai", "juni",
"juli", "agust", "september", "oktober", "november", "desember"
},
*IT_months [] = {
"gennaio", "febbraio", "marzo", "aprile", "maggio", "giugno",
"luglio", "agosto", "settembre", "ottobre", "novembre", "dicembre"
},
*NL_months [] = {
"januari", "februari", "mars", "april", "mei", "juni",
"juli", "augustus", "september", "oktober", "november", "december"
},
*NO_months [] = {
"januar", "februar", "mars", "april", "mai", "juni",
"juli", "august", "september", "oktober", "november", "desember"
},
*PO_months [] = {
"janeiro", "fevereiro", "mar噊", "abril", "maio", "junho",
"julho", "agosto", "setembro", "outubro", "novembro", "dezembro"
},
*SV_months [] = {
"januari", "februari", "mars", "april", "maj", "juni",
"juli", "augusti", "september", "oktober", "november", "december"
};
static char
*EN_days [] = {
"Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday"
},
*FR_days [] = {
"Dimanche", "Lundi", "Mardi", "Mercredi",
"Jeudi", "Vendredi", "Samedi"
},
*NL_days [] = {
"Zondag", "Maandag", "Dinsdag", "Woensdag",
"Donderdag", "Vrijdag", "Zaterdag"
};
static int
user_language = 0; /* 0 = default language */
static Bool
use_accents = TRUE;
static char
**units_table = EN_units,
**tens_table = EN_tens,
**day_table = EN_days,
**month_table = EN_months;
/* Local function prototypes */
static char *handle_accents (char *string);
/* ---------------------------------------------------------------------[<]-
Function: set_userlang
Synopsis: Sets language used for date and numeric translation.
The valid user languages are:
<TABLE>
USERLANG_DEFAULT Default language (use hard-coded values)
USERLANG_DA Danish
USERLANG_DE German
USERLANG_EN English
USERLANG_ES Castillian Spanish
USERLANG_FB Belgian or Swiss French
USERLANG_FR French
USERLANG_IS Icelandic
USERLANG_IT Italian
USERLANG_NL Dutch
USERLANG_NO Norwegian
USERLANG_PO Portuguese
USERLANG_SV Swedish
</TABLE>
Returns 0 if okay, -1 if an unsupported language was specified.
---------------------------------------------------------------------[>]-*/
int
set_userlang (int language)
{
/* Order of this table is not critical */
static struct {
int language;
char **units;
char **tens;
char **days;
char **months;
} languages [] =
{
{ USERLANG_DEFAULT, EN_units, EN_tens, EN_days, EN_months },
{ USERLANG_DA, DA_units, DA_tens, EN_days, DA_months },
{ USERLANG_DE, DE_units, DE_tens, EN_days, DE_months },
{ USERLANG_EN, EN_units, EN_tens, EN_days, EN_months },
{ USERLANG_ES, ES_units, ES_tens, EN_days, ES_months },
{ USERLANG_FB, FR_units, FB_tens, FR_days, FR_months },
{ USERLANG_FR, FR_units, FR_tens, FR_days, FR_months },
{ USERLANG_IS, IS_units, IS_tens, EN_days, IS_months },
{ USERLANG_IT, IT_units, IT_tens, EN_days, IT_months },
{ USERLANG_NL, NL_units, NL_tens, NL_days, NL_months },
{ USERLANG_NO, NO_units, NO_tens, EN_days, NO_months },
{ USERLANG_PO, PO_units, PO_tens, EN_days, PO_months },
{ USERLANG_SV, SV_units, SV_tens, EN_days, SV_months },
{ -1, NULL, NULL, NULL, NULL }
};
int
index;
for (index = 0; languages [index].language != -1; index++)
if (languages [index].language == language)
{
user_language = language;
units_table = languages [index].units;
tens_table = languages [index].tens;
day_table = languages [index].days;
month_table = languages [index].months;
return (0);
}
return (-1);
}
/* ---------------------------------------------------------------------[<]-
Function: set_userlang_str
Synopsis: Sets language used for date and numeric translation, using a
string representation of the language. The valid user languages are:
<TABLE>
"" Default language (use hard-coded values)
"--" Alternative form for default language
"DA" Danish
"DE" German
"EN" English
"ES" Castillian Spanish
"FB" Belgian or Swiss French
"FR" French
"IS" Icelandic
"IT" Italian
"NL" Dutch
"NO" Norwegian
"PO" Portuguese
"SV" Swedish
</TABLE>
Returns 0 if okay, -1 if an unsupported language was specified.
---------------------------------------------------------------------[>]-*/
int
set_userlang_str (const char *language)
{
int
index;
if (strnull (language))
return (set_userlang (USERLANG_DEFAULT));
for (index = 0; index < USERLANG_TOP; index++)
if (streq (language, language_str [index]))
return (set_userlang (index));
return (-1);
}
/* ---------------------------------------------------------------------[<]-
Function: get_userlang
Synopsis: Returns the current user language code.
---------------------------------------------------------------------[>]-*/
int
get_userlang (void)
{
return (user_language);
}
/* ---------------------------------------------------------------------[<]-
Function: get_userlang_str
Synopsis: Returns the current user language as a 2-character string.
---------------------------------------------------------------------[>]-*/
char *
get_userlang_str (void)
{
return (language_str [user_language]);
}
/* ---------------------------------------------------------------------[<]-
Function: set_accents
Synopsis: Enables or disables native-language accents. If enabled,
accented characters in translated words are produced in the current
system character set, if possible. Otherwise, suitable translations
are made into the 26-letter English alphabet. By default, accents are
enabled.
---------------------------------------------------------------------[>]-*/
int
set_accents (Bool accents)
{
use_accents = accents;
return (0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -