mirror of
https://github.com/pbatard/rufus.git
synced 2025-05-27 21:24:17 -04:00
[loc] add [v]ersion command support
This commit is contained in:
parent
d3a495aa83
commit
44cc7ea652
8 changed files with 107 additions and 38 deletions
|
@ -49,7 +49,7 @@ const loc_parse parse_cmd[9] = {
|
|||
// Base translation to add on top of (eg. "English (UK)" can be used to build on top of "English (US)"
|
||||
{ 'b', LC_BASE, "s" }, // b "en_US"
|
||||
// Version to use for the localization commandset and API
|
||||
{ 'v', LC_VERSION, "ii" }, // v 1.0 // TODO: NOT IMPLEMENTED YET
|
||||
{ 'v', LC_VERSION, "u" }, // v 1.0.2
|
||||
// Translate the text control associated with an ID
|
||||
{ 't', LC_TEXT, "cs" }, // t IDC_CONTROL "Translation"
|
||||
// Set the section/dialog to which the next commands should apply
|
||||
|
@ -331,9 +331,6 @@ void _exit_localization(BOOL reinit) {
|
|||
|
||||
/*
|
||||
* Validate and store localization command data
|
||||
*
|
||||
* TODO: Do we need to store a revert for every action we execute here,
|
||||
* or do we want to reinstantiate the dialogs?
|
||||
*/
|
||||
BOOL dispatch_loc_cmd(loc_cmd* lcmd)
|
||||
{
|
||||
|
@ -373,10 +370,6 @@ BOOL dispatch_loc_cmd(loc_cmd* lcmd)
|
|||
dlg_index = lcmd->ctrl_id - IDD_DIALOG;
|
||||
free_loc_cmd(lcmd);
|
||||
break;
|
||||
case LC_VERSION:
|
||||
luprintf("GOT VERSION: %d.%d\n", lcmd->num[0], lcmd->num[1]);
|
||||
free_loc_cmd(lcmd);
|
||||
break;
|
||||
case LC_BASE:
|
||||
base_locale = get_locale_from_name(lcmd->txt[0], FALSE);
|
||||
if (base_locale != NULL) {
|
||||
|
@ -401,7 +394,6 @@ err:
|
|||
/*
|
||||
* Apply stored localization commands to a specific dialog
|
||||
* If hDlg is NULL, apply the commands against an active Window
|
||||
* TODO: if dlg_id is <0, apply all
|
||||
*/
|
||||
void apply_localization(int dlg_id, HWND hDlg)
|
||||
{
|
||||
|
|
|
@ -23,9 +23,13 @@
|
|||
#pragma once
|
||||
|
||||
// Number of concurrent localization messages. Must be a power of 2.
|
||||
#define LOC_MESSAGE_NB 8
|
||||
#define LOC_MESSAGE_SIZE 2048
|
||||
#define LOC_HTAB_SIZE 512
|
||||
#define LOC_MESSAGE_NB 8
|
||||
#define LOC_MESSAGE_SIZE 2048
|
||||
#define LOC_HTAB_SIZE 512
|
||||
|
||||
// The [v]ersion major from a translation must match this number or
|
||||
// the translation will be ignored
|
||||
#define LOC_FRAMEWORK_VERSION 1
|
||||
|
||||
#define luprint(msg) uprintf("%s(%d): " msg "\n", loc_filename, loc_line_nr)
|
||||
#define luprintf(msg, ...) uprintf("%s(%d): " msg "\n", loc_filename, loc_line_nr, __VA_ARGS__)
|
||||
|
|
85
src/parser.c
85
src/parser.c
|
@ -122,18 +122,18 @@ static loc_cmd* get_loc_cmd(char c, char* line) {
|
|||
goto err;
|
||||
}
|
||||
break;
|
||||
case 'u': // comma separated list of unsigned integers (to end of line)
|
||||
case 'u': // comma or dot separated list of unsigned integers (to end of line)
|
||||
// count the number of commas
|
||||
lcmd->unum_size = 1;
|
||||
for (l=i; line[l] != 0; l++) {
|
||||
if (line[l] == ',')
|
||||
if ((line[l] == '.') || (line[l] == ','))
|
||||
lcmd->unum_size++;
|
||||
}
|
||||
lcmd->unum = (uint32_t*)malloc(lcmd->unum_size * sizeof(uint32_t));
|
||||
token = strtok(&line[i], ",");
|
||||
token = strtok(&line[i], ".,");
|
||||
for (l=0; (l<lcmd->unum_size) && (token != NULL); l++) {
|
||||
lcmd->unum[l] = (int32_t)strtol(token, &endptr, 0);
|
||||
token = strtok(NULL, ",");
|
||||
token = strtok(NULL, ".,");
|
||||
}
|
||||
if ((token != NULL) || (l != lcmd->unum_size)) {
|
||||
luprint("internal error (unexpected number of numeric values)");
|
||||
|
@ -234,6 +234,8 @@ BOOL get_supported_locales(const char* filename)
|
|||
size_t i;
|
||||
loc_cmd *lcmd = NULL, *last_lcmd = NULL;
|
||||
long end_of_block;
|
||||
int version_line_nr = 0;
|
||||
uint32_t loc_base_minor = -1, loc_base_micro = -1;
|
||||
|
||||
fd = open_loc_file(filename);
|
||||
if (fd == NULL)
|
||||
|
@ -250,29 +252,78 @@ BOOL get_supported_locales(const char* filename)
|
|||
loc_line_nr++;
|
||||
// Skip leading spaces
|
||||
i = strspn(line, space);
|
||||
if (line[i] != 'l')
|
||||
if ((line[i] != 'l') && (line[i] != 'v'))
|
||||
continue;
|
||||
// line[i] is not NUL so i+1 is safe to access
|
||||
lcmd = get_loc_cmd(line[i], &line[i+1]);
|
||||
if ((lcmd == NULL) || (lcmd->command != LC_LOCALE)) {
|
||||
if ((lcmd == NULL) || ((lcmd->command != LC_LOCALE) && (lcmd->command != LC_VERSION))) {
|
||||
free_loc_cmd(lcmd);
|
||||
continue;
|
||||
}
|
||||
// we use num[0] and num[1] as block delimiter index for this locale in the file
|
||||
if (last_lcmd != NULL) {
|
||||
last_lcmd->num[1] = (int32_t)end_of_block;
|
||||
switch (lcmd->command) {
|
||||
case LC_LOCALE:
|
||||
// we use num[0] and num[1] as block delimiter index for this locale in the file
|
||||
if (last_lcmd != NULL) {
|
||||
if (version_line_nr == 0) {
|
||||
uprintf("localization: no compatible version was found - this locale will be ignored\n");
|
||||
list_del(&last_lcmd->list);
|
||||
free_loc_cmd(last_lcmd);
|
||||
} else {
|
||||
last_lcmd->num[1] = (int32_t)end_of_block;
|
||||
}
|
||||
}
|
||||
lcmd->num[0] = (int32_t)ftell(fd);
|
||||
// Add our locale command to the locale list
|
||||
list_add_tail(&lcmd->list, &locale_list);
|
||||
uprintf("localization: found locale '%s'\n", lcmd->txt[0]);
|
||||
last_lcmd = lcmd;
|
||||
version_line_nr = 0;
|
||||
break;
|
||||
case LC_VERSION:
|
||||
if (version_line_nr != 0) {
|
||||
luprintf("[v]ersion was already provided at line %d", version_line_nr);
|
||||
} else if (lcmd->unum_size != 3) {
|
||||
luprint("[v]ersion format is invalid");
|
||||
} else if (last_lcmd == NULL) {
|
||||
luprint("[v]ersion cannot precede [l]ocale");
|
||||
} else if (lcmd->unum[0] != LOC_FRAMEWORK_VERSION) {
|
||||
// If the localization framework evolved in a manner that makes existing
|
||||
// translations incompatible, we need to discard them.
|
||||
luprint("[v]ersion is not compatible with this framework");
|
||||
} else if (loc_base_minor == -1) {
|
||||
// We use the first version from our loc file (usually en-US) as our base
|
||||
// as it should always be the most up to date.
|
||||
loc_base_minor = lcmd->unum[1];
|
||||
loc_base_micro = lcmd->unum[0];
|
||||
version_line_nr = loc_line_nr;
|
||||
} else if (lcmd->unum[1] < loc_base_minor) {
|
||||
luprintf("the version of this locale is incompatible with this version of " APPLICATION_NAME " and MUST be updated to at least v%d.%d.0",
|
||||
LOC_FRAMEWORK_VERSION, loc_base_minor);
|
||||
} else {
|
||||
if (lcmd->unum[2] < loc_base_micro) {
|
||||
luprintf("the version of this translation is older than the base one and may result in some messages not being properly translated.\n"
|
||||
"If you are the translator, please update your translation with the changes that intervened between v%d.%d.%d and v%d.%d.%d.\n"
|
||||
"See https://github.com/pbatard/rufus/blob/master/res/localization/ChangeLog.txt",
|
||||
LOC_FRAMEWORK_VERSION, loc_base_minor, lcmd->unum[2], LOC_FRAMEWORK_VERSION, loc_base_minor, loc_base_micro);
|
||||
}
|
||||
version_line_nr = loc_line_nr;
|
||||
}
|
||||
free_loc_cmd(lcmd);
|
||||
break;
|
||||
}
|
||||
lcmd->num[0] = (int32_t)ftell(fd);
|
||||
// Add our locale command to the locale list
|
||||
list_add_tail(&lcmd->list, &locale_list);
|
||||
uprintf("localization: found locale '%s'\n", lcmd->txt[0]);
|
||||
last_lcmd = lcmd;
|
||||
} while (1);
|
||||
if (last_lcmd != NULL)
|
||||
last_lcmd->num[1] = (int32_t)ftell(fd);
|
||||
if (last_lcmd != NULL) {
|
||||
if (version_line_nr == 0) {
|
||||
uprintf("localization: no compatible version was found - this locale will be ignored\n");
|
||||
list_del(&last_lcmd->list);
|
||||
free_loc_cmd(last_lcmd);
|
||||
} else {
|
||||
last_lcmd->num[1] = (int32_t)ftell(fd);
|
||||
}
|
||||
}
|
||||
r = !list_empty(&locale_list);
|
||||
if (r == FALSE)
|
||||
uprintf("localization: '%s' contains no locale sections\n", filename);
|
||||
uprintf("localization: '%s' contains no valid locale sections\n", filename);
|
||||
|
||||
out:
|
||||
if (fd != NULL)
|
||||
|
|
|
@ -2033,7 +2033,9 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
|||
if ( (!get_supported_locales(loc_file))
|
||||
|| ((selected_locale = ((locale_name == NULL)?get_locale_from_lcid(lcid, TRUE):get_locale_from_name(locale_name, TRUE))) == NULL) ) {
|
||||
uprintf("FATAL: Could not access locale!\n");
|
||||
MessageBoxU(NULL, "The locale data is missing. This application will now exit.",
|
||||
MessageBoxU(NULL, "The locale data is missing or invalid. This application will now exit."
|
||||
// TODO: remove this line for release!
|
||||
"\n\nTRANSLATORS: You need to add a 'v 1.0.0' line to your loc file. See the latest 'new_translation.loc'",
|
||||
"Fatal error", MB_ICONSTOP);
|
||||
goto out;
|
||||
}
|
||||
|
|
10
src/rufus.rc
10
src/rufus.rc
|
@ -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.0.299"
|
||||
CAPTION "Rufus v1.4.0.300"
|
||||
FONT 8, "MS Shell Dlg", 400, 0, 0x1
|
||||
BEGIN
|
||||
DEFPUSHBUTTON "Start",IDC_START,94,291,50,14
|
||||
|
@ -285,8 +285,8 @@ END
|
|||
//
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION 1,4,0,299
|
||||
PRODUCTVERSION 1,4,0,299
|
||||
FILEVERSION 1,4,0,300
|
||||
PRODUCTVERSION 1,4,0,300
|
||||
FILEFLAGSMASK 0x3fL
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS 0x1L
|
||||
|
@ -303,13 +303,13 @@ BEGIN
|
|||
BEGIN
|
||||
VALUE "CompanyName", "Akeo Consulting (http://akeo.ie)"
|
||||
VALUE "FileDescription", "Rufus"
|
||||
VALUE "FileVersion", "1.4.0.299"
|
||||
VALUE "FileVersion", "1.4.0.300"
|
||||
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.0.299"
|
||||
VALUE "ProductVersion", "1.4.0.300"
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue