[loc] use a direct table for the messages

* More efficient and also the first step for addressing #188
This commit is contained in:
Pete Batard 2013-12-18 01:20:44 +00:00
parent c9d44a5303
commit f3cf32f8d8
8 changed files with 92 additions and 54 deletions

View File

@ -6,6 +6,9 @@ the same changes.
Remember to also update the version number for your translation ('v x.y.z')
once you have matched all the changes that occurred for the en-US translation.
o Version 1.0.6 (2013.12.17)
- Removed IDD_MESSAGES (and the need for 'g IDD_MESSAGES')
o Version 1.0.5 (2013.12.11)
- Removed MSG_092 to MSG_094

View File

@ -11,7 +11,7 @@ s/[ \t]*$//
# remove the UI controls for "en-US" as they are just here for translators
# 1,300 means we only do this for the the first 300 lines
1,300 {/^g IDD_DIALOG/,/^g IDD_MESSAGES/{/^g IDD_MESSAGES/!d}}
1,300 {/^g IDD_DIALOG/,/^t MSG_001/{/^t MSG_001/!d}}
# also replace the "translated by" line for English
1,500{s/^t MSG_176.*$/t MSG_176 \"mailto:pete@akeo.ie\"/}

View File

@ -53,7 +53,7 @@
# http://download.microsoft.com/download/9/5/E/95EF66AF-9026-4BB0-A41D-A4F81802D92C/%5BMS-LCID%5D.pdf
# for the LCID (0x####) codes you should use
l "en-US" "English (English)" 0x0409, 0x0809, 0x0c09, 0x1009, 0x1409, 0x1809, 0x1c09, 0x2009, 0x2409, 0x2809, 0x2c09, 0x3009, 0x3409, 0x3809, 0x3c09, 0x4009, 0x4409, 0x4809
v 1.0.5
v 1.0.6
# Main dialog
g IDD_DIALOG
@ -131,7 +131,6 @@ t IDC_ISO_FILENAME "Opening ISO image - please wait..."
t IDC_ISO_ABORT "Cancel"
# Messages used throughout the application
g IDD_MESSAGES
t MSG_001 "Other instance detected"
t MSG_002 "Another Rufus application is running.\n"
"Please close the first application before running another one."
@ -494,7 +493,7 @@ t IDD_ISO_EXTRACT "复制ISO文件..."
t IDC_ISO_FILENAME "打开ISO映像 - 请稍候..."
t IDC_ISO_ABORT "取消"
g IDD_MESSAGES
# Messages used throughout the application
t MSG_004 "更新方案和设置"
t MSG_005 "你要允許此應用程序檢查更新?"
t MSG_006 "关闭"
@ -503,7 +502,7 @@ t MSG_176 ""
################################################################################
l "zh-TW" "Chinese Traditional (正體中文)" 0x0404, 0x0c04, 0x1404, 0x7c04
v 1.0.5
v 1.0.6
b "en-US"
# Main dialog
@ -585,7 +584,6 @@ t IDC_ISO_FILENAME "讀取映像檔中,請稍候..."
t IDC_ISO_ABORT "取消"
# Messages used throughout the application
g IDD_MESSAGES
t MSG_001 "錯誤"
t MSG_002 "已有 Rufus 視窗執行中\n"
"若要重新開啟,請先終止執行中的視窗"
@ -850,7 +848,7 @@ t MSG_259 "Force update"
################################################################################
l "nl-NL" "Dutch (Netherlands)" 0x0413, 0x0813
v 1.0.5
v 1.0.6
b "en-US"
# Main dialog
@ -957,7 +955,6 @@ t IDC_ISO_FILENAME "Bezig met openen ISO image - Een moment geduld a.u.b...."
t IDC_ISO_ABORT "Annuleer"
# Messages used throughout the application
g IDD_MESSAGES
t MSG_001 "Ander programma gedetecteerd"
t MSG_002 "Een andere Rufus applicatie is geopend.\n"
"Sluit de eerste applicatie voordat u een andere opent a.u.b."
@ -1230,7 +1227,7 @@ t MSG_259 "Forceer update"
################################################################################
l "fr-FR" "French (Français)" 0x040c, 0x080c, 0x0c0c, 0x100c, 0x140c, 0x180c, 0x1c0c, 0x200c, 0x240c, 0x280c, 0x2c0c, 0x300c, 0x340c, 0x380c, 0xe40c
v 1.0.5
v 1.0.6
b "en-US"
g IDD_DIALOG
@ -1313,7 +1310,7 @@ t IDD_ISO_EXTRACT "Copie des fichier ISO..."
t IDC_ISO_FILENAME "Ouverture de l'image - veuillez patienter..."
t IDC_ISO_ABORT "Annuler"
g IDD_MESSAGES
# Messages used throughout the application
t MSG_001 "Autre instance detectée"
t MSG_002 "Une autre instance de Rufus est en cours d'exécution.\n"
"Veuillez fermer la première instance avant d'en lancer une seconde."
@ -1572,7 +1569,7 @@ t MSG_259 "Forçage de mise à jour"
################################################################################
l "de-DE" "German (Deutsch)" 0x0407, 0x0807, 0x0c07, 0x1007, 0x1407
v 1.0.5
v 1.0.6
b "en-US"
g IDD_DIALOG
@ -1671,7 +1668,7 @@ t IDD_ISO_EXTRACT "Kopiere ISO-Dateien..."
t IDC_ISO_FILENAME "Öffne ISO-Abbild - bitte warten..."
t IDC_ISO_ABORT "Abbruch"
g IDD_MESSAGES
# Messages used throughout the application
t MSG_001 "Rufus ist bereits gestartet"
t MSG_002 "Rufus ist bereits gestartet.\n"
"Bitte schließen Sie es erst, bevor Sie es neue starten."
@ -1943,7 +1940,7 @@ t MSG_259 "Update erzwingen"
################################################################################
l "el-GR" "Greek (Ελληνικά)" 0x0408
v 1.0.5
v 1.0.6
b "en-US"
# Main dialog
@ -2073,7 +2070,6 @@ t IDC_ISO_FILENAME "Άνοιγμα αρχείου ISO - παρακαλώ περ
t IDC_ISO_ABORT "Ακύρωση"
# Messages used throughout the application
g IDD_MESSAGES
t MSG_001 "Ανιχνεύθηκε άλλη εφαρμογή Rufus"
t MSG_002 "Η εφαρμογή Rufus εκτελείται ήδη.\n"
"Παρακαλώ κλείστε την πρώτη εφαρμογή πριν εκτελέσετε μία άλλη."
@ -2352,7 +2348,7 @@ t MSG_259 "Εξαναγκασμένη ενημέρωση"
################################################################################
l "hu-HU" "Hungarian (Magyar)" 0x040e
v 1.0.5
v 1.0.6
b "en-US"
# Main dialog
@ -2426,7 +2422,6 @@ t IDC_ISO_FILENAME "ISO fájl megnyitása - kérlek, várj..."
t IDC_ISO_ABORT "Mégse"
# Messages used throughout the application
g IDD_MESSAGES
t MSG_001 "Másik folyamat"
t MSG_002 "Egy másik Rufus is fut.\n"
"Kérlek, zárd be a másikat, mielőtt ezt futtatnád."
@ -2710,7 +2705,7 @@ t MSG_259 "'Erőszakos' frissítés"
################################################################################
l "it-IT" "Italian (Italiano)" 0x0410, 0x0810
v 1.0.5
v 1.0.6
b "en-US"
g IDD_DIALOG
@ -2807,7 +2802,7 @@ t IDD_ISO_EXTRACT "Copia file ISO..."
t IDC_ISO_FILENAME "Apertura file immagine ISO..."
t IDC_ISO_ABORT "Annulla"
g IDD_MESSAGES
# Messages used throughout the application
t MSG_001 "Rilevata altra istanza Rufus"
t MSG_002 "E' in esecuzione un altra applicazioen Rufus.\n"
"Chiudi la prima applicazione prima di eseguirna una seconda."
@ -3067,7 +3062,7 @@ t MSG_258 "Supporto Rock Ridge"
################################################################################
l "ko-KR" "Korean (한국어)" 0x0412
v 1.0.5
v 1.0.6
b "en-US"
# Main dialog
@ -3157,7 +3152,6 @@ t IDC_ISO_FILENAME "ISO 이미지 파일을 여는 중입니다. - 잠시만..."
t IDC_ISO_ABORT "취소"
# Messages used throughout the application
g IDD_MESSAGES
t MSG_001 "다른 인스턴스가 감지 됨."
t MSG_002 "Rufus가 이미 실행 중입니다.\n"
"실행하기 전에 먼저 실행된 프로그램을 닫으십시오."
@ -3442,7 +3436,7 @@ t MSG_259 "강제 업데이트"
################################################################################
l "lt-LT" "Lithuanian (Lietuvių)" 0x0427
v 1.0.5
v 1.0.6
b "en-US"
# Main dialog
@ -3555,7 +3549,6 @@ t IDC_ISO_FILENAME "Atidaromas ISO atvaizdas - palaukite..."
t IDC_ISO_ABORT "Atšaukti"
# Messages used throughout the application
g IDD_MESSAGES
t MSG_001 "Aptiktas kitas programos atvejis"
t MSG_002 "Vykdoma kita Rufus programa.\n"
"Prašau uždaryti pirmą programą prieš vykdant kitą."
@ -3840,7 +3833,7 @@ t MSG_259 "Priversti naujintis"
################################################################################
l "ms-MY" "Malay (Bahasa Malaysia)" 0x043e, 0x083e
v 1.0.5
v 1.0.6
b "en-US"
# Main dialog
@ -3956,7 +3949,6 @@ t IDC_ISO_FILENAME "Membuka imej ISO - tunggu sebentar..."
t IDC_ISO_ABORT "Batal"
# Messages used throughout the application
g IDD_MESSAGES
t MSG_001 "Proses Rufus lain dikesan"
t MSG_002 "Terdapat aplikasi Rufus sedang berjalan.\n"
"Sila tutup aplikasi tersebut sebelum melancarkan aplikasi Rufus baharu."
@ -4242,7 +4234,7 @@ t MSG_259 "Paksa kemas kini"
################################################################################
l "pl-PL" "Polish (Polski)" 0x0415
v 1.0.5
v 1.0.6
b "en-US"
# my internal info: 01.12.2013,21:03 (finito); DONE: szerokości głównego
@ -4357,7 +4349,6 @@ t IDC_ISO_FILENAME "Otwieranie obrazu ISO - proszę czekać..."
t IDC_ISO_ABORT "Anuluj"
# Messages used throughout the application
g IDD_MESSAGES
t MSG_001 "Wykryto inną instancję"
t MSG_002 "Inna aplikacja Rufus jest uruchomiona.\n"
"Proszę zamknąć pierwszą aplikację przed otwarciem innej."
@ -4642,7 +4633,7 @@ t MSG_259 "Siłowa aktualizacja"
################################################################################
l "ro-RO" "Romanian (Română)" 0x0418, 0x0818
v 1.0.5
v 1.0.6
b "en-US"
g IDD_DIALOG
@ -4741,7 +4732,7 @@ t IDD_ISO_EXTRACT "Copiere fişiere ISO..."
t IDC_ISO_FILENAME "Deschiderea fişier imagine ISO..."
t IDC_ISO_ABORT "Anulează"
g IDD_MESSAGES
# Messages used throughout the application
t MSG_001 "Un alt exemplu detectat Rufus"
t MSG_002 "Rulează o altă aplicaţie Rufus. \ N"
"Închideţi prima aplicaţie înainte de a efectua a doua."
@ -4993,7 +4984,7 @@ t MSG_259 "Actualizare forţată"
################################################################################
l "ru-RU" "Russian (Русский)" 0x0419, 0x0819
v 1.0.5
v 1.0.6
b "en-US"
# Main dialog
@ -5117,7 +5108,6 @@ t IDC_ISO_FILENAME "Открытие ISO-образа - пожалуйста, ж
t IDC_ISO_ABORT "Отмена"
# Messages used throughout the application
g IDD_MESSAGES
t MSG_001 "Запущено другое приложение Rufus"
t MSG_002 "Запущено другое приложение Rufus.\n"
"Закройте первое приложение перед запуском еще одного."
@ -5383,7 +5373,7 @@ t MSG_258 "Rock Ridge поддержка"
################################################################################
l "sl-SI" "Slovenian (Slovenščina)" 0x0424
v 1.0.5
v 1.0.6
b "en-US"
# Main dialog
@ -5485,7 +5475,6 @@ t IDC_ISO_FILENAME "Odpiram ISO sliko - prosim, počakajte…"
t IDC_ISO_ABORT "Prekliči"
# Messages used throughout the application
g IDD_MESSAGES
t MSG_001 "Drug primerek zaznan"
t MSG_002 "Še en primerek Rufusa se izvaja.\n"
"Prosim, zaprite ga, preden zaženete še enega."
@ -5770,7 +5759,7 @@ t MSG_259 "Prisili posodobitev"
################################################################################
l "es-ES" "Spanish (Español)" 0x040a, 0x080a, 0x0c0a, 0x100a, 0x140a, 0x180a, 0x1c0a, 0x200a, 0x240a, 0x280a, 0x2c0a, 0x300a, 0x340a, 0x380a, 0x3c0a, 0x400a, 0x440a, 0x480a, 0x4c0a, 0x500a, 0x540a, 0x580a
v 1.0.5
v 1.0.6
b "en-US"
# Main dialog
@ -5881,7 +5870,6 @@ t IDC_ISO_FILENAME "Abriendo la imagen ISO - por favor, espere..."
t IDC_ISO_ABORT "Cancelar"
# Messages used throughout the application
g IDD_MESSAGES
t MSG_001 "Se detectó otra instancia"
t MSG_002 "Ya hay una intancia de Rufus ejecutándose.\n"
"Cierre la primer instancia antes de lanzar otra."
@ -6172,7 +6160,7 @@ t MSG_259 "Forzar actualización"
################################################################################
l "tr-TR" "Turkish (Türkçe)" 0x041F
v 1.0.5
v 1.0.6
b "en-US"
# Main dialog
@ -6282,7 +6270,6 @@ t IDC_ISO_FILENAME "ISO Görüntüsü Açılıyor - Lütfen Bekleyin..."
t IDC_ISO_ABORT "Vazgeç"
# Messages used throughout the application
g IDD_MESSAGES
t MSG_001 "Rufus'un zaten çalıştığı algılandı"
t MSG_002 "Başka bir Rufus uygulaması çalışıyor.\n"
"Lütfen başka bir uygulama çalıştırmak için ilkini kapatın."

View File

@ -183,6 +183,7 @@ static BOOLEAN __stdcall ChkdskCallback(FILE_SYSTEM_CALLBACK_COMMAND Command, DW
FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_DEVICE_IN_USE;
break;
case FCC_OUTPUT:
// TODO: convert from sys CP to UTF-8
uprintf("%s\n", ((PTEXTOUTPUT)pData)->Output);
break;
case FCC_NO_MEDIA_IN_DRIVE:
@ -718,6 +719,7 @@ static BOOL CheckDisk(char DriveLetter)
}
}
// TODO: set locale to en-US
pfChkdsk(wDriveRoot, wFSType, FALSE, FALSE, FALSE, FALSE, NULL, NULL, ChkdskCallback);
if (!IS_ERROR(FormatStatus)) {
uprintf("NTFS Fixup completed.\n");

View File

@ -71,6 +71,17 @@ int loc_line_nr;
struct list_head locale_list = {NULL, NULL};
char *loc_filename = NULL, *embedded_loc_filename = "embedded.loc";
/* Message table */
char* msg_table[MSG_MAX-MSG_000] = {0};
static void mtab_destroy(void)
{
size_t j;
for (j=0; j<MSG_MAX-MSG_000; j++) {
safe_free(msg_table[j]);
}
}
/*
* Hash table functions - modified From glibc 2.3.2:
* [Aho,Sethi,Ullman] Compilers: Principles, Techniques and Tools, 1986
@ -271,6 +282,26 @@ void add_dialog_command(int index, loc_cmd* lcmd)
list_add(&lcmd->list, &loc_dlg[index].list);
}
/*
* Add a translated message to a direct lookup table
*/
void add_message_command(loc_cmd* lcmd)
{
if (lcmd == NULL) {
uprintf("localization: invalid parameter for add_message_command\n");
return;
}
if ((lcmd->ctrl_id <= MSG_000) || (lcmd->ctrl_id >= MSG_MAX)) {
uprintf("localization: invalid MSG_ index\n");
return;
}
safe_free(msg_table[lcmd->ctrl_id-MSG_000]);
msg_table[lcmd->ctrl_id-MSG_000] = lcmd->txt[1];
lcmd->txt[1] = NULL; // String would be freed after this call otherwise
}
void free_loc_cmd(loc_cmd* lcmd)
{
if (lcmd == NULL)
@ -314,8 +345,10 @@ void _init_localization(BOOL reinit) {
size_t i;
for (i=0; i<ARRAYSIZE(loc_dlg); i++)
list_init(&loc_dlg[i].list);
if (!reinit)
if (!reinit) {
list_init(&locale_list);
mtab_destroy();
}
htab_create(LOC_HTAB_SIZE);
}
@ -326,6 +359,7 @@ void _exit_localization(BOOL reinit) {
safe_free(loc_filename);
}
free_dialog_list();
mtab_destroy();
htab_destroy();
}
@ -337,12 +371,29 @@ BOOL dispatch_loc_cmd(loc_cmd* lcmd)
size_t i;
static int dlg_index = 0;
loc_cmd* base_locale = NULL;
const char* msg_prefix = "MSG_";
if (lcmd == NULL)
return FALSE;
if (lcmd->command <= LC_TEXT) {
// Any command up to LC_TEXT takes a control ID in text[0]
if (safe_strncmp(lcmd->txt[0], msg_prefix, 4) == 0) {
if (lcmd->command != LC_TEXT) {
luprint("only the 't' command can be applied to a message (MSG_###)\n");
goto err;
}
// Try to convert the numeric part of a MSG_#### to a numeric
lcmd->ctrl_id = MSG_000 + atoi(&lcmd->txt[0][4]);
if (lcmd->ctrl_id == MSG_000) {
// Conversion could not be performed
luprintf("failed to convert the numeric value in '%'\n", lcmd->txt[0]);
goto err;
}
add_message_command(lcmd);
free_loc_cmd(lcmd);
return TRUE;
}
for (i=0; i<ARRAYSIZE(control_id); i++) {
if (safe_strcmp(lcmd->txt[0], control_id[i].name) == 0) {
lcmd->ctrl_id = control_id[i].id;
@ -417,9 +468,8 @@ void apply_localization(int dlg_id, HWND hDlg)
if ((!IsWindow(hDlg)) || (list_empty(&loc_dlg[dlg_id-IDD_DIALOG].list)))
continue;
// TODO: storing the messages in an array indexed on the message ID - 3000 would be faster
list_for_each_entry(lcmd, &loc_dlg[dlg_id-IDD_DIALOG].list, loc_cmd, list) {
if (lcmd->command <= LC_TEXT) { // TODO: should always be the case
if (lcmd->command <= LC_TEXT) {
if (lcmd->ctrl_id == dlg_id) {
if ((dlg_id == IDD_DIALOG) && (lcmd->txt[1] != NULL) && (lcmd->txt[1][0] != 0)) {
loc_line_nr = lcmd->line_nr;
@ -440,14 +490,13 @@ void apply_localization(int dlg_id, HWND hDlg)
}
switch(lcmd->command) {
// NB: For commands that take an ID, ctrl_id is always a valid index at this stage
case LC_TEXT:
if (hCtrl != NULL) {
if ((lcmd->txt[1] != NULL) && (lcmd->txt[1][0] != 0))
SetWindowTextU(hCtrl, lcmd->txt[1]);
if (left_to_right) {
style = GetWindowLongPtr(hCtrl, GWL_EXSTYLE);
style |= WS_EX_LAYOUTRTL; // WS_EX_RIGHT | WS_EX_RTLREADING
style |= WS_EX_LAYOUTRTL; // TODO: WS_EX_RIGHT | WS_EX_RTLREADING
SetWindowLongPtr(hCtrl, GWL_EXSTYLE, style);
InvalidateRect(hCtrl, NULL, TRUE);
}
@ -491,13 +540,11 @@ char* lmprintf(int msg_id, ...)
static char buf[LOC_MESSAGE_NB][LOC_MESSAGE_SIZE];
char *format = NULL;
va_list args;
loc_cmd* lcmd;
buf_id %= LOC_MESSAGE_NB;
buf[buf_id][0] = 0;
list_for_each_entry(lcmd, &loc_dlg[IDD_MESSAGES-IDD_DIALOG].list, loc_cmd, list) {
if ((lcmd->command == LC_TEXT) && (lcmd->ctrl_id == msg_id) && (lcmd->txt[1] != NULL)) {
format = lcmd->txt[1];
}
if ((msg_id > MSG_000) && (msg_id < MSG_MAX)) {
format = msg_table[msg_id - MSG_000];
}
if (format == NULL) {

View File

@ -35,7 +35,6 @@ const loc_control_id control_id[] = {
LOC_CTRL(IDD_LOG),
LOC_CTRL(IDD_UPDATE_POLICY),
LOC_CTRL(IDD_NEW_VERSION),
LOC_CTRL(IDD_MESSAGES),
LOC_CTRL(IDC_DEVICE),
LOC_CTRL(IDC_FILESYSTEM),
LOC_CTRL(IDC_START),
@ -359,6 +358,7 @@ const loc_control_id control_id[] = {
LOC_CTRL(MSG_257),
LOC_CTRL(MSG_258),
LOC_CTRL(MSG_259),
LOC_CTRL(MSG_MAX),
LOC_CTRL(IDOK),
LOC_CTRL(IDCANCEL),
LOC_CTRL(IDABORT),
@ -380,5 +380,4 @@ loc_dlg_list loc_dlg[] = {
LOC_DLG(IDD_LOG),
LOC_DLG(IDD_UPDATE_POLICY),
LOC_DLG(IDD_NEW_VERSION),
LOC_DLG(IDD_MESSAGES),
};

View File

@ -10,7 +10,6 @@
#define IDD_LOG 106
#define IDD_UPDATE_POLICY 107
#define IDD_NEW_VERSION 108
#define IDD_MESSAGES 109
#define IDI_ICON 110
#define IDI_UP 111
#define IDI_DOWN 112
@ -370,6 +369,7 @@
#define MSG_257 3257
#define MSG_258 3258
#define MSG_259 3259
#define MSG_MAX 3260
// Next default values for new objects
//

View File

@ -33,7 +33,7 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
IDD_DIALOG DIALOGEX 12, 12, 206, 329
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_APPWINDOW
CAPTION "Rufus v1.4.2.356"
CAPTION "Rufus v1.4.2.357"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
DEFPUSHBUTTON "Start",IDC_START,94,291,50,14
@ -288,8 +288,8 @@ END
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,4,2,356
PRODUCTVERSION 1,4,2,356
FILEVERSION 1,4,2,357
PRODUCTVERSION 1,4,2,357
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
@ -306,13 +306,13 @@ BEGIN
BEGIN
VALUE "CompanyName", "Akeo Consulting (http://akeo.ie)"
VALUE "FileDescription", "Rufus"
VALUE "FileVersion", "1.4.2.356"
VALUE "FileVersion", "1.4.2.357"
VALUE "InternalName", "Rufus"
VALUE "LegalCopyright", "© 2011-2013 Pete Batard (GPL v3)"
VALUE "LegalTrademarks", "http://www.gnu.org/copyleft/gpl.html"
VALUE "OriginalFilename", "rufus.exe"
VALUE "ProductName", "Rufus"
VALUE "ProductVersion", "1.4.2.356"
VALUE "ProductVersion", "1.4.2.357"
END
END
BLOCK "VarFileInfo"