Commit 7aa3b62af2ed839789e65f7aeeedb73b6ee200ea
1 parent
38f03821
improvement of L3 lib
Showing
3 changed files
with
327 additions
and
58 deletions
Show diff stats
anubis_dev/library/locale/L3.anubis
| 1 | - | |
| 1 | + /* | |
| 2 | 2 | *Project* The Anubis Project |
| 3 | 3 | |
| 4 | 4 | *Title* The Local Language Library. |
| ... | ... | @@ -52,7 +52,7 @@ |
| 52 | 52 | |
| 53 | 53 | the extensions are in accordance with ISO-639-1 and ISO-639-2 language |
| 54 | 54 | representation. |
| 55 | - | |
| 55 | +*/ | |
| 56 | 56 | |
| 57 | 57 | |
| 58 | 58 | read tools/basis.anubis |
| ... | ... | @@ -76,11 +76,26 @@ public type L3Symbol: //define the symbol attributes |
| 76 | 76 | l3Symbol( String name, //the name of symbol |
| 77 | 77 | String chapter, //the chapter of symbol |
| 78 | 78 | String description //the description of the content text define by the symbol |
| 79 | + ). | |
| 80 | + | |
| 81 | +public type L3SymbolFull: //define the symbol attributes with all properties | |
| 82 | + l3Symbol( String name, //the name of symbol | |
| 83 | + String chapter, //the chapter of symbol | |
| 84 | + String description, //the description of the content text define by the symbol | |
| 85 | + Int32 creation_date, //creation date of this symbol | |
| 86 | + Int32 last_update //update date of this symbol | |
| 79 | 87 | ). |
| 80 | 88 | public type L3Text: //couple that define the |
| 81 | 89 | l3Text( String symbolic_name, //symbolic name and his |
| 82 | 90 | String translation_text //translation text |
| 83 | 91 | ). |
| 92 | + | |
| 93 | +public type L3TextFull: //couple that define the | |
| 94 | + l3Text( String symbolic_name, //symbolic name and his | |
| 95 | + String translation_text, //translation text | |
| 96 | + Int32 creation_date, | |
| 97 | + Int32 last_update | |
| 98 | + ). | |
| 84 | 99 | |
| 85 | 100 | public type L3: |
| 86 | 101 | l3( String appName, //name of application |
| ... | ... | @@ -92,6 +107,24 @@ public type L3: |
| 92 | 107 | SQLite3DataBase currentLangDb //SQLite database of current language |
| 93 | 108 | ). |
| 94 | 109 | |
| 110 | +public type L3Properties: | |
| 111 | + l3Properties | |
| 112 | + ( String appName, //name of application | |
| 113 | + String appHash, //unique id of the application | |
| 114 | + String default_lang, | |
| 115 | + Int32 creation_date, | |
| 116 | + Int32 last_update | |
| 117 | + ). | |
| 118 | + | |
| 119 | +public type L3LangDicProperty: | |
| 120 | + l3LangDicProperty | |
| 121 | + ( String appHash, //unique id of the application | |
| 122 | + String lang_code, | |
| 123 | + String userdef, | |
| 124 | + Int32 creation_date, | |
| 125 | + Int32 last_update | |
| 126 | + ). | |
| 127 | + | |
| 95 | 128 | public define Maybe(L3) l3_load_base (String appName). |
| 96 | 129 | public define Bool l3_create_base (String appName , String language). |
| 97 | 130 | public define Bool l3_base_exists (String appName , String language). |
| ... | ... | @@ -129,25 +162,47 @@ public define Bool is_text(SQLite3DataBase lang_db, String symbolic_name) = |
| 129 | 162 | }. |
| 130 | 163 | |
| 131 | 164 | |
| 132 | - | |
| 133 | -define Bool put_text(SQLite3DataBase lang_db, String symbolic_name, String translation) = | |
| 165 | +/** put text translation into symbol entry in the given database. If the symbol | |
| 166 | + * doesn't exist in datadabe, it's created before. But if any occures during the | |
| 167 | + * creation or updating a false value is return. | |
| 168 | + * @param lang_db database in which we want put the text | |
| 169 | + * @param symbolic_name name of which symbol we want to put the text | |
| 170 | + * @param translation the text to be stored in the database in symbol_name location | |
| 171 | + * @return true if no problem occure otherwise false. | |
| 172 | + **/ | |
| 173 | +define Bool | |
| 174 | + put_text | |
| 175 | + ( | |
| 176 | + SQLite3DataBase lang_db, | |
| 177 | + String symbolic_name, | |
| 178 | + String translation | |
| 179 | + ) = | |
| 180 | + //get current date for update date field in database | |
| 181 | + with current_date = (Int32)now, | |
| 134 | 182 | if is_text(lang_db, symbolic_name) is |
| 135 | 183 | { |
| 136 | 184 | //if the text doesn't exist, we ADD in the table |
| 137 | 185 | false then |
| 138 | - if sql_query(lang_db, "INSERT INTO symbol (name, translation) VALUES ('" + symbolic_name +"', '" +translation+"')") is | |
| 186 | + if sql_query(lang_db, "INSERT INTO symbol (name, translation, creationDate, lastUpdate) VALUES ('" + symbolic_name +"', '" +translation+"', "+ current_date+", "+ current_date+")") is | |
| 139 | 187 | error(n) then false |
| 140 | 188 | else |
| 141 | 189 | true |
| 142 | - //if the text already exist, we UPDATE the value | |
| 190 | + //if the text already exist, we UPDATE the value of the text and the date of update | |
| 143 | 191 | true then |
| 144 | - if sql_query(lang_db, "UPDATE symbol SET translation = '" + translation + "' WHERE name = '" + symbolic_name + "'") is | |
| 192 | + if sql_query(lang_db, "UPDATE symbol SET translation = '" + translation + "', lastUpdate = " + current_date + ", WHERE name = '" + symbolic_name + "'") is | |
| 145 | 193 | error(n) then false |
| 146 | 194 | else |
| 147 | 195 | true |
| 148 | 196 | }. |
| 149 | 197 | |
| 150 | -public define Bool put_text(L3 currentApp, String symbolic_name, String language, String text) = | |
| 198 | +public define Bool | |
| 199 | + put_text | |
| 200 | + ( | |
| 201 | + L3 currentApp, | |
| 202 | + String symbolic_name, | |
| 203 | + String language, | |
| 204 | + String text | |
| 205 | + ) = | |
| 151 | 206 | if currentApp is l3( appName, _, symbol_db, _, _, _, _) then |
| 152 | 207 | //check if the symbol already exist in symbol database |
| 153 | 208 | if is_symbol(currentApp, symbolic_name) is |
| ... | ... | @@ -161,10 +216,18 @@ public define Bool put_text(L3 currentApp, String symbolic_name, String language |
| 161 | 216 | } |
| 162 | 217 | }. |
| 163 | 218 | |
| 164 | -to do: here check if the symbol already exist in the database | |
| 165 | -public define Bool put_symbol(L3 l3object, String symbolic_name, String chapter, String description) = | |
| 219 | +//TODO here check if the symbol already exist in the database | |
| 220 | +public define Bool | |
| 221 | + put_symbol | |
| 222 | + ( | |
| 223 | + L3 l3object, | |
| 224 | + String symbolic_name, | |
| 225 | + String chapter, | |
| 226 | + String description | |
| 227 | + ) = | |
| 166 | 228 | if l3object is l3( _, _, symboldb, _, _ , _, _) then |
| 167 | - if sql_query(symboldb,"INSERT INTO symbol (name, chapter, description, translation) VALUES ('" + symbolic_name +"', '"+chapter+"','" +description+"','" + symbolic_name +"')") is | |
| 229 | + with current_date = (Int32)now, | |
| 230 | + if sql_query(symboldb,"INSERT INTO symbol (name, chapter, description, translation, creationDate, lastUpdate) VALUES ('" + symbolic_name +"', '"+chapter+"','" +description+"','" + symbolic_name +"', "+ current_date+", "+ current_date+")") is | |
| 168 | 231 | error(n) then db_print_error(n ,"can't insert symbol [" + symbolic_name +"] into database");false |
| 169 | 232 | else |
| 170 | 233 | true. |
| ... | ... | @@ -237,10 +300,10 @@ public define String get_text(L3 l3object, String symbolic_name) = |
| 237 | 300 | [description] |
| 238 | 301 | |
| 239 | 302 | define Bool create_symbol_tables(SQLite3DataBase db) = |
| 240 | - if sql_query(db, "CREATE TABLE info ( appSignature text, defaultLanguage text, creationDate integer, lastUpdate integer)") is | |
| 303 | + if sql_query(db, "CREATE TABLE info (appName text, appSignature text, defaultLanguage text, creationDate integer, lastUpdate integer)") is | |
| 241 | 304 | error(n) then db_print_error(n, "create_symbol_tables: Can't create info Table"); false |
| 242 | 305 | else |
| 243 | - if sql_query(db, "CREATE TABLE symbol ( name text PRIMARY KEY, chapter text, description text, translation text)") is | |
| 306 | + if sql_query(db, "CREATE TABLE symbol ( name text PRIMARY KEY, chapter text, description text, translation text, creationDate integer, lastUpdate integer)") is | |
| 244 | 307 | error(n) then db_print_error(n, "create_symbol_tables: Can't create symbol Table"); false |
| 245 | 308 | else |
| 246 | 309 | true. |
| ... | ... | @@ -266,10 +329,10 @@ define Bool create_symbol_tables(SQLite3DataBase db) = |
| 266 | 329 | [translation] |
| 267 | 330 | |
| 268 | 331 | define Bool create_language_tables(SQLite3DataBase db) = |
| 269 | - if sql_query(db, "CREATE TABLE info ( appSignature text, language text, userDefine text, creationDate integer, lastUpdate integer)") is | |
| 332 | + if sql_query(db, "CREATE TABLE info (appSignature text, language text, userDefine text, creationDate integer, lastUpdate integer)") is | |
| 270 | 333 | error(n) then db_print_error(n, "create_language_tables: Can't create info Table"); false |
| 271 | 334 | else |
| 272 | - if sql_query(db, "CREATE TABLE symbol ( name text PRIMARY KEY, translation text)") is | |
| 335 | + if sql_query(db, "CREATE TABLE symbol ( name text PRIMARY KEY, translation text, creationDate integer, lastUpdate integer)") is | |
| 273 | 336 | error(n) then db_print_error(n, "create_language_tables: Can't create translate_data Table"); false |
| 274 | 337 | else |
| 275 | 338 | true. |
| ... | ... | @@ -311,24 +374,174 @@ define Bool l3_base_exists(String appName, String languageExtension) = |
| 311 | 374 | else |
| 312 | 375 | print("l3_base_exists: false ["+appName + ".L3." + languageExtension+"] \n"); false. |
| 313 | 376 | |
| 377 | + /* *************************** DICTIONARY FUNCTIONS ************************* */ | |
| 378 | + | |
| 314 | 379 | define List(String) is_dic(List(String) current, List(String) test) = |
| 315 | 380 | if test is |
| 316 | 381 | { |
| 317 | 382 | [] then current, |
| 318 | 383 | [h . t] then is_dic([ h . current ], t) |
| 319 | - } | |
| 320 | -. | |
| 384 | + }. | |
| 321 | 385 | |
| 322 | 386 | define List(String) construct_dic_list(List(String) file_list)= |
| 323 | 387 | if file_list is |
| 324 | 388 | { |
| 325 | 389 | [] then [], |
| 326 | 390 | [h . t ] then is_dic( [], file_list) |
| 391 | + }. | |
| 392 | + | |
| 393 | +public define List(String) l3_get_all_dic = | |
| 394 | + construct_dic_list(directory_list( my_anubis_directory + "/dictionnaries/", "*.L3.symb")). | |
| 395 | + | |
| 396 | + | |
| 397 | +/* ******************************** ********************************** */ | |
| 398 | + | |
| 399 | +define Maybe(L3LangDicProperty) | |
| 400 | + fill_l3_lang_prop | |
| 401 | + ( | |
| 402 | + Int32 -> SQLite3Datum row | |
| 403 | + ) = | |
| 404 | + with app_sha1 = text(row)(0), | |
| 405 | + lang_code = text(row)(1), | |
| 406 | + user_def = text(row)(2), | |
| 407 | + if integer(row)(3) is | |
| 408 | + { | |
| 409 | + failure then failure, | |
| 410 | + success(creation_date) then | |
| 411 | + if integer(row)(4) is | |
| 412 | + { | |
| 413 | + failure then failure, | |
| 414 | + success(last_update) then | |
| 415 | + success(l3LangDicProperty(app_sha1, lang_code, user_def, creation_date, last_update)) | |
| 416 | + }}. | |
| 417 | + | |
| 418 | +public define Maybe(L3LangDicProperty) | |
| 419 | + l3_get_lang_property_of | |
| 420 | + ( | |
| 421 | + String l3_db_name | |
| 422 | + ) = | |
| 423 | + if sqlite3_open(my_anubis_directory +"/dictionnaries/" + l3_db_name) is | |
| 424 | + { | |
| 425 | + error(Int32 n) then db_print_error(n, " Cannot open database.");failure | |
| 426 | + ok(SQLite3DataBase db) then | |
| 427 | + if sql_query(db, "SELECT * FROM info") is | |
| 428 | + { | |
| 429 | + error(n) then failure, | |
| 430 | + ok(table_cursor) then | |
| 431 | + if table_cursor(unique) is | |
| 432 | + { | |
| 433 | + failure then failure, | |
| 434 | + success(row) then fill_l3_lang_prop(row) | |
| 435 | + } | |
| 436 | + } | |
| 327 | 437 | } |
| 328 | -. | |
| 329 | -public define List(String) l3_get_all_dic(One dummy) = | |
| 330 | - construct_dic_list(directory_list( my_anubis_directory + "/dictionnaries/", "*.L3.symb")) | |
| 331 | -. | |
| 438 | + . | |
| 439 | + | |
| 440 | +define List(L3LangDicProperty) | |
| 441 | + is_dic | |
| 442 | + ( | |
| 443 | + List(L3LangDicProperty) current, | |
| 444 | + List(String) test | |
| 445 | + ) = | |
| 446 | + | |
| 447 | + if test is | |
| 448 | + { | |
| 449 | + [] then current, | |
| 450 | + [h . t] then is_dic( if l3_get_lang_property_of(h) is | |
| 451 | + { | |
| 452 | + failure then current, | |
| 453 | + success(prop) then [prop . current ] | |
| 454 | + } | |
| 455 | + , t) | |
| 456 | + }. | |
| 457 | + | |
| 458 | +define List(L3LangDicProperty) | |
| 459 | + construct_sub_dic_list | |
| 460 | + ( | |
| 461 | + List(String) file_list | |
| 462 | + )= | |
| 463 | + if file_list is | |
| 464 | + { | |
| 465 | + [] then [], | |
| 466 | + [h . t ] then is_dic( [], file_list) | |
| 467 | + }. | |
| 468 | + | |
| 469 | +public define List(L3LangDicProperty) | |
| 470 | + l3_get_all_sub_dic | |
| 471 | + ( | |
| 472 | + String dic_name | |
| 473 | + )= | |
| 474 | + construct_sub_dic_list(directory_list( my_anubis_directory + "/dictionnaries/", dic_name+".L3.*")). | |
| 475 | + . | |
| 476 | + | |
| 477 | +define Maybe(L3Properties) | |
| 478 | + fill_l3_prop | |
| 479 | + ( | |
| 480 | + Int32 -> SQLite3Datum row | |
| 481 | + ) = | |
| 482 | + with app_name = text(row)(0), | |
| 483 | + app_signature = text(row)(1), | |
| 484 | + def_lang = text(row)(2), | |
| 485 | + if integer(row)(3) is | |
| 486 | + { | |
| 487 | + failure then failure, | |
| 488 | + success(creation_date) then | |
| 489 | + if integer(row)(4) is | |
| 490 | + { | |
| 491 | + failure then failure, | |
| 492 | + success(last_update) then | |
| 493 | + success(l3Properties(app_name, app_signature, def_lang, creation_date, last_update)) | |
| 494 | + }}. | |
| 495 | + | |
| 496 | +public define Maybe(L3Properties) | |
| 497 | + l3_get_properties_of | |
| 498 | + ( | |
| 499 | + String l3_db_name | |
| 500 | + ) = | |
| 501 | + | |
| 502 | + if sqlite3_open(my_anubis_directory +"/dictionnaries/" + l3_db_name) is | |
| 503 | + { | |
| 504 | + error(Int32 n) then db_print_error(n, " Cannot open database.");failure | |
| 505 | + ok(SQLite3DataBase db) then | |
| 506 | + if sql_query(db, "SELECT * FROM info") is | |
| 507 | + { | |
| 508 | + error(n) then failure, | |
| 509 | + ok(table_cursor) then | |
| 510 | + if table_cursor(unique) is | |
| 511 | + { | |
| 512 | + failure then failure, | |
| 513 | + success(row) then fill_l3_prop(row) | |
| 514 | + } | |
| 515 | + } | |
| 516 | + } | |
| 517 | + . | |
| 518 | + | |
| 519 | +define List(L3Properties) | |
| 520 | + is_dic | |
| 521 | + ( | |
| 522 | + List(L3Properties) current, | |
| 523 | + List(String) test | |
| 524 | + ) = | |
| 525 | + if test is | |
| 526 | + { | |
| 527 | + [] then current, | |
| 528 | + [h . t] then is_dic( if l3_get_properties_of(h) is | |
| 529 | + { | |
| 530 | + failure then current, | |
| 531 | + success(prop) then [prop . current ] | |
| 532 | + } | |
| 533 | + , t) | |
| 534 | + }. | |
| 535 | + | |
| 536 | +define List(L3Properties) construct_dic_list(List(String) file_list)= | |
| 537 | + if file_list is | |
| 538 | + { | |
| 539 | + [] then [], | |
| 540 | + [h . t ] then is_dic( [], file_list) | |
| 541 | + }. | |
| 542 | + | |
| 543 | +public define List(L3Properties) l3_get_all_dic = | |
| 544 | + construct_dic_list(directory_list( my_anubis_directory + "/dictionnaries/", "*.L3.symb")). | |
| 332 | 545 | |
| 333 | 546 | define Bool create_L3_default_dir(One none) = |
| 334 | 547 | if make_directory(my_anubis_directory+"/dictionnaries/", default_directory_mode) is |
| ... | ... | @@ -355,7 +568,7 @@ public define Bool l3_create_base (String appName, String languageExtension) = |
| 355 | 568 | with appSignature = to_ascii(sha1(appName + now)), |
| 356 | 569 | with creationDate = (Int32)now, |
| 357 | 570 | print("appSignature :" + appSignature); |
| 358 | - if sql_query(db,"INSERT INTO info (appSignature, defaultLanguage, creationDate, lastUpdate) VALUES ('" + appSignature +"', 'symbolic', "+creationDate+"," +creationDate+")") is | |
| 571 | + if sql_query(db,"INSERT INTO info (appName, appSignature, defaultLanguage, creationDate, lastUpdate) VALUES ('" + appName +"', '" + appSignature +"', 'symbolic', "+creationDate+"," +creationDate+")") is | |
| 359 | 572 | error(n) then db_print_error(n ,"can't insert value into database");false |
| 360 | 573 | else |
| 361 | 574 | true |
| ... | ... | @@ -375,7 +588,8 @@ public define Bool l3_create_base (String appName, String languageExtension) = |
| 375 | 588 | else |
| 376 | 589 | print("ERROR: Can't create directory ["+ my_anubis_directory+"/dictionnaries/]\n"); false |
| 377 | 590 | . |
| 378 | - | |
| 591 | +/** Add the language to the L3 | |
| 592 | + */ | |
| 379 | 593 | public define Maybe(SQLite3DataBase) l3_add_language(L3 currentApp, String l3langCode, Int32 userDefined, Bool default) = |
| 380 | 594 | if currentApp is l3(appName, appHash, _, _, _, _, _) then |
| 381 | 595 | if l3_base_exists( appName, l3langCode) is | ... | ... |
anubis_dev/library/locale/L3LanguageInfo.anubis
| 1 | - | |
| 1 | + | |
| 2 | 2 | read tools/basis.anubis |
| 3 | 3 | read system/string.anubis |
| 4 | - | |
| 4 | +read locale/iso3166-1.anubis | |
| 5 | + | |
| 5 | 6 | public type L3LanguageCode: |
| 6 | 7 | symbolic, |
| 7 | 8 | iso639_1(String), |
| 8 | 9 | iso639_2(String), |
| 9 | - other(String). | |
| 10 | + other(String). | |
| 11 | + | |
| 12 | +public type L3CountryCode: | |
| 13 | + symbolic, | |
| 14 | + iso3166_1(String), | |
| 15 | + other(String). | |
| 10 | 16 | |
| 11 | 17 | public type L3LanguageInfo: |
| 12 | 18 | lang_info(List(L3LanguageCode) codes, // like "en", "fr", ... |
| ... | ... | @@ -19,12 +25,11 @@ public type L3LanguageInfo: |
| 19 | 25 | |
| 20 | 26 | |
| 21 | 27 | |
| 22 | -define String datef_dmy ( Int32 dat ) = | |
| 28 | +public define String datef_dmy ( Int32 dat ) = | |
| 23 | 29 | with d = convert_time(dat), |
| 24 | 30 | zero_pad_n(2,day(d))+"/"+zero_pad_n(2,month(d)+1)+"/"+year(d). |
| 25 | 31 | |
| 26 | - | |
| 27 | -define String datef_ymd ( Int32 dat ) = | |
| 32 | +public define String datef_ymd ( Int32 dat ) = | |
| 28 | 33 | with d = convert_time(dat), |
| 29 | 34 | year(d)+"/"+zero_pad_n(2,month(d)+1)+"/"+zero_pad_n(2,day(d)). |
| 30 | 35 | |
| ... | ... | @@ -32,7 +37,7 @@ public define String datee_ymd = "yyyy/mm/dd". |
| 32 | 37 | public define String datee_dmy = "dd/mm/yyyy". |
| 33 | 38 | |
| 34 | 39 | |
| 35 | -define String dhour_format ( Int32 dat ) = | |
| 40 | +public define String dhour_format ( Int32 dat ) = | |
| 36 | 41 | with d = convert_time(dat), |
| 37 | 42 | zero_pad_n(2,hour(d))+":"+zero_pad_n(2,minute(d))+":"+zero_pad_n(2,second(d)). |
| 38 | 43 | |
| ... | ... | @@ -52,16 +57,16 @@ public define List(L3LanguageInfo) |
| 52 | 57 | standard_languages |
| 53 | 58 | = |
| 54 | 59 | [ |
| 55 | - lang_info([symbolic],"symbolic", "symobic", "", datef_ymd, datee_ymd, dhour_format), | |
| 60 | + lang_info([symbolic],"symbolic", "symbolic", "", datef_ymd, datee_ymd, dhour_format), | |
| 56 | 61 | lang_info([iso639_1("eu"),iso639_2("baq"),iso639_2("eus")],"basque", "basque", "", datef_dmy, datee_dmy, dhour_format), |
| 57 | 62 | lang_info([iso639_1("be"),iso639_2("bre")],"breton", "breton", "", datef_dmy, datee_dmy, dhour_format), |
| 58 | - lang_info([iso639_1("bg"),iso639_2("bul")],"bulgarian", "bulgarian", "", datef_dmy, datee_dmy, dhour_format), | |
| 59 | - lang_info([iso639_1("da"),iso639_2("dan")],"danish", "danish", "", datef_dmy, datee_dmy, dhour_format), | |
| 60 | - lang_info([iso639_1("en"),iso639_2("eng")],"english", "english", "", datef_dmy, datee_dmy, dhour_format), | |
| 61 | - lang_info([iso639_1("fr"),iso639_2("fre"),iso639_2("fra")],"french", "français", "", datef_dmy, datee_dmy, dhour_format), | |
| 62 | - lang_info([iso639_1("zh"),iso639_2("zho"),iso639_2("chi")],"chinese", "中文", "", datef_ymd, datee_ymd, dhour_format), | |
| 63 | - lang_info([iso639_1("ja"),iso639_2("jpn")],"japanese", "日本語", "", datef_ymd, datee_ymd, dhour_format), | |
| 64 | - lang_info([iso639_1("de"),iso639_2("deu"),iso639_2("ger")],"german", "deutsch", "", datef_dmy, datee_dmy, dhour_format), | |
| 63 | + lang_info([iso639_1("bg"),iso639_2("bul")],"bulgarian", "bulgarian", "", datef_dmy, datee_dmy, dhour_format), | |
| 64 | + lang_info([iso639_1("da"),iso639_2("dan")],"danish", "danish", "", datef_dmy, datee_dmy, dhour_format), | |
| 65 | + lang_info([iso639_1("en"),iso639_2("eng")],"english", "english", "", datef_dmy, datee_dmy, dhour_format), | |
| 66 | + lang_info([iso639_1("fr"),iso639_2("fre"),iso639_2("fra")],"french", "français", "", datef_dmy, datee_dmy, dhour_format), | |
| 67 | + lang_info([iso639_1("zh"),iso639_2("zho"),iso639_2("chi")],"chinese", "中文", "", datef_ymd, datee_ymd, dhour_format), | |
| 68 | + lang_info([iso639_1("ja"),iso639_2("jpn")],"japanese", "日本語", "", datef_ymd, datee_ymd, dhour_format), | |
| 69 | + lang_info([iso639_1("de"),iso639_2("deu"),iso639_2("ger")],"german", "deutsch", "", datef_dmy, datee_dmy, dhour_format), | |
| 65 | 70 | lang_info([other("Stroumpf")],"Stroumpf","Stroumpf","", datef_dmy, datee_dmy, dhour_format) |
| 66 | 71 | //lang_info("nl", offline, "flag_nl.gif", nl_texts, datef_ymd, datee_ymd, dhour_format,"dutch"), |
| 67 | 72 | //lang_info("pl", online, "flag_pl.gif", pl_texts, datef_dmy, datee_dmy, dhour_format,"polish") |
| ... | ... | @@ -74,24 +79,57 @@ public define List(L3LanguageInfo) |
| 74 | 79 | public define L3LanguageInfo symbolic_lang_info = |
| 75 | 80 | lang_info([symbolic], "Symbolic", "Symbolic", "", datef_ymd, datee_ymd, dhour_format). |
| 76 | 81 | |
| 82 | +public define L3LanguageInfo unknown_lang_info = | |
| 83 | + lang_info([other("unknown")], "unknown", "unknown", "", datef_ymd, datee_ymd, dhour_format). | |
| 77 | 84 | |
| 78 | 85 | |
| 79 | 86 | *** () Getting language informations from the language code. |
| 80 | 87 | |
| 81 | -define Maybe(L3LanguageInfo) get_language_info ( L3LanguageCode langcode, List(L3LanguageInfo) l ) = | |
| 88 | +define L3LanguageInfo | |
| 89 | + get_language_info | |
| 90 | + ( | |
| 91 | + String langcode, | |
| 92 | + List(L3LanguageInfo) l | |
| 93 | + ) = | |
| 82 | 94 | if l is |
| 83 | 95 | { |
| 84 | - [ ] then failure, | |
| 85 | - [h . t] then if h is lang_info(codes, e_name, s_name, flag, fd, ed, hf) then | |
| 86 | - if member(codes, langcode) | |
| 87 | - then success(h) | |
| 96 | + [ ] then unknown_lang_info, | |
| 97 | + [h . t] then if h is lang_info(codes, e_name, s_name, flag, fd, ed, hf) then | |
| 98 | + if (langcode = "symb") & member(codes, symbolic) then h | |
| 99 | + else print("iso639_1 " +langcode+ "\n"); if member(codes, iso639_1(langcode)) then h | |
| 100 | + else print("iso639_2 " +langcode+ "\n"); if member(codes, iso639_2(langcode)) then h | |
| 101 | + else print("other " +langcode+ "\n");if member(codes, other(langcode)) then h | |
| 88 | 102 | else get_language_info(langcode,t) |
| 89 | 103 | }. |
| 90 | 104 | |
| 91 | - | |
| 92 | -public define Maybe(L3LanguageInfo) get_language_info ( L3LanguageCode langcode ) = | |
| 105 | +define L3LanguageInfo | |
| 106 | + get_language_info | |
| 107 | + ( | |
| 108 | + L3LanguageCode langcode, | |
| 109 | + List(L3LanguageInfo) l | |
| 110 | + ) = | |
| 111 | + if l is | |
| 112 | + { | |
| 113 | + [ ] then unknown_lang_info, | |
| 114 | + [h . t] then if h is lang_info(codes, e_name, s_name, flag, fd, ed, hf) then | |
| 115 | + if member(codes, langcode) then h | |
| 116 | + else | |
| 117 | + get_language_info(langcode,t) | |
| 118 | + }. | |
| 119 | + | |
| 120 | +public define L3LanguageInfo | |
| 121 | + l3_get_language_info | |
| 122 | + ( | |
| 123 | + String langcode | |
| 124 | + ) = | |
| 93 | 125 | get_language_info(langcode, standard_languages). |
| 94 | 126 | |
| 127 | +public define L3LanguageInfo | |
| 128 | + get_language_info | |
| 129 | + ( | |
| 130 | + L3LanguageCode langcode | |
| 131 | + ) = | |
| 132 | + get_language_info(langcode, standard_languages). | |
| 95 | 133 | |
| 96 | 134 | |
| 97 | 135 | |
| ... | ... | @@ -99,11 +137,7 @@ public define Maybe(L3LanguageInfo) get_language_info ( L3LanguageCode langcode |
| 99 | 137 | *** () Getting the date format |
| 100 | 138 | |
| 101 | 139 | public define Int32 -> String date_format ( L3LanguageCode lg_code ) = |
| 102 | - if get_language_info(lg_code) is | |
| 103 | - { | |
| 104 | - failure then datef_ymd, | |
| 105 | - success(L3LanguageInfo i) then format_date(i) | |
| 106 | - } . | |
| 140 | + format_date(get_language_info(lg_code, standard_languages)) . | |
| 107 | 141 | |
| 108 | 142 | if find_element(languages,(L3LanguageInfo li) |-> language_code(li)=lg_code) is |
| 109 | 143 | { |
| ... | ... | @@ -113,7 +147,8 @@ public define Int32 -> String date_format ( L3LanguageCode lg_code ) = |
| 113 | 147 | |
| 114 | 148 | |
| 115 | 149 | public define String explain_date_format ( L3LanguageCode lg_code ) = |
| 116 | - if get_language_info(lg_code) is | |
| 150 | + explain_date(get_language_info(lg_code, standard_languages)). | |
| 151 | + is | |
| 117 | 152 | { |
| 118 | 153 | failure then datee_ymd, |
| 119 | 154 | success(L3LanguageInfo i) then explain_date(i) |
| ... | ... | @@ -123,9 +158,9 @@ public define String explain_date_format ( L3LanguageCode lg_code ) = |
| 123 | 158 | *** () Getting the hour format |
| 124 | 159 | |
| 125 | 160 | public define Int32 -> String hour_format ( L3LanguageCode lg_code ) = |
| 126 | - if get_language_info(lg_code) is | |
| 161 | + hour_format(get_language_info(lg_code, standard_languages)). is | |
| 127 | 162 | { |
| 128 | 163 | failure then dhour_format, |
| 129 | 164 | success(L3LanguageInfo i) then hour_format(i) |
| 130 | 165 | }. |
| 131 | - | |
| 132 | 166 | \ No newline at end of file |
| 167 | + | ... | ... |
anubis_dev/library/test/locale_test.anubis
| ... | ... | @@ -55,6 +55,16 @@ public define List(L3Text) |
| 55 | 55 | ]. |
| 56 | 56 | |
| 57 | 57 | public define List(L3Text) |
| 58 | + chinese_text | |
| 59 | + = | |
| 60 | + [l3Text("hello" , "字母" ), | |
| 61 | + l3Text("ok" , "对" ), | |
| 62 | + l3Text("apply" , "涂" ), | |
| 63 | + l3Text("cancel" , "取消" ), | |
| 64 | + l3Text("help" , "助手" ) | |
| 65 | + ]. | |
| 66 | + | |
| 67 | +public define List(L3Text) | |
| 58 | 68 | japanese_text |
| 59 | 69 | = |
| 60 | 70 | [l3Text("hello" , "こにちは" ), |
| ... | ... | @@ -63,7 +73,7 @@ public define List(L3Text) |
| 63 | 73 | l3Text("cancel" , "キャンセル" ), |
| 64 | 74 | l3Text("help" , "助け" ) |
| 65 | 75 | ]. |
| 66 | - | |
| 76 | + | |
| 67 | 77 | define Bool locale_test_put_symbols(L3 l3base, List(L3Symbol) symbols) = |
| 68 | 78 | if symbols is |
| 69 | 79 | { |
| ... | ... | @@ -154,20 +164,30 @@ global define One locale_test (List (String) args) = |
| 154 | 164 | true then print("French text added\n"), |
| 155 | 165 | } |
| 156 | 166 | }; |
| 157 | - if l3_add_language(locale, "jp", (Int32)0, false) is | |
| 167 | + if l3_add_language(locale, "zho", (Int32)0, false) is | |
| 168 | + { | |
| 169 | + failure then print("can't load database \"locale_test\" "); unique, | |
| 170 | + success(_) then | |
| 171 | + if locale_test_put_texts(locale, "zho", chinese_text) is | |
| 172 | + { | |
| 173 | + false then print("Can't add chinese text\n") | |
| 174 | + true then print("Chinese text added\n"), | |
| 175 | + } | |
| 176 | + }; | |
| 177 | + if l3_add_language(locale, "ja", (Int32)0, false) is | |
| 158 | 178 | { |
| 159 | 179 | failure then print("can't load database \"locale_test\" "); unique, |
| 160 | 180 | success(_) then |
| 161 | - if locale_test_put_texts(locale, "jp", japanese_text) is | |
| 181 | + if locale_test_put_texts(locale, "ja", japanese_text) is | |
| 162 | 182 | { |
| 163 | 183 | false then print("Can't add japanese text\n") |
| 164 | - true then print("French text added\n"), | |
| 184 | + true then print("Japanese text added\n"), | |
| 165 | 185 | } |
| 166 | 186 | }; |
| 167 | 187 | with locale = l3_set_default(locale, "en"), |
| 168 | 188 | with locale = l3_set_current(locale, "fr"), |
| 169 | 189 | print("hello in fr is " + get_text(locale, "hello") +"\n"); |
| 170 | - forget(map((String s) |-> print(s+" \n"), l3_get_all_dic(unique))) | |
| 190 | + forget(map((String s) |-> print(s+" \n"), l3_get_all_dic)) | |
| 171 | 191 | |
| 172 | 192 | }. |
| 173 | 193 | ... | ... |