From 639a1e8ef948aab199e4c078a8c29bc6a38cce04 Mon Sep 17 00:00:00 2001 From: jdgordon Date: Sat, 26 Sep 2009 00:58:32 +0000 Subject: [PATCH] new skin tag: %Sx|| will display the current languages translation of the "" string. the is the Source: bit in the .lang files. (must be exactly as it is there...) checkwps cannot verify that the string is correct so make sure to use the sim to verify the string is acurate. Also "fix" checkwps so %St|| can be accepted for the theme site git-svn-id: svn://svn.rockbox.org/rockbox/trunk@22837 a1c6a512-1295-4272-9138-f99709370657 --- apps/gui/skin_engine/skin_parser.c | 59 ++++++++++++++++++++++++++------------ apps/gui/skin_engine/skin_tokens.c | 3 ++ apps/gui/skin_engine/skin_tokens.h | 1 + apps/gui/skin_engine/wps_debug.c | 3 ++ apps/language.c | 13 +++++++++ apps/language.h | 3 ++ 6 files changed, 64 insertions(+), 18 deletions(-) diff --git a/apps/gui/skin_engine/skin_parser.c b/apps/gui/skin_engine/skin_parser.c index efe9f5228..e62d47340 100644 --- a/apps/gui/skin_engine/skin_parser.c +++ b/apps/gui/skin_engine/skin_parser.c @@ -40,6 +40,7 @@ #endif /*WPSEDITOR*/ #else #include "debug.h" +#include "language.h" #endif /*__PCTOOL__*/ #include @@ -132,7 +133,7 @@ static int parse_progressbar(const char *wps_bufptr, struct wps_token *token, struct wps_data *wps_data); static int parse_dir_level(const char *wps_bufptr, struct wps_token *token, struct wps_data *wps_data); -static int parse_setting(const char *wps_bufptr, +static int parse_setting_and_lang(const char *wps_bufptr, struct wps_token *token, struct wps_data *wps_data); #ifdef HAVE_LCD_BITMAP @@ -349,8 +350,11 @@ static const struct wps_tag all_tags[] = { #endif #endif - { WPS_TOKEN_SETTING, "St", WPS_REFRESH_DYNAMIC, parse_setting }, - + { WPS_TOKEN_SETTING, "St", WPS_REFRESH_DYNAMIC, + parse_setting_and_lang }, + { WPS_TOKEN_TRANSLATEDSTRING, "Sx", WPS_REFRESH_STATIC, + parse_setting_and_lang }, + { WPS_TOKEN_LASTTOUCH, "Tl", WPS_REFRESH_DYNAMIC, parse_timeout }, { WPS_NO_TOKEN, "T", 0, parse_touchregion }, @@ -746,14 +750,20 @@ static int parse_image_special(const char *wps_bufptr, #endif /* HAVE_LCD_BITMAP */ -static int parse_setting(const char *wps_bufptr, - struct wps_token *token, - struct wps_data *wps_data) +static int parse_setting_and_lang(const char *wps_bufptr, + struct wps_token *token, + struct wps_data *wps_data) { + /* NOTE: both the string validations that happen in here will + * automatically PASS on checkwps because its too hard to get + * settings_list.c and englinsh.lang built for it. + * If that ever changes remove the #ifndef __PCTOOL__'s here + */ (void)wps_data; const char *ptr = wps_bufptr; const char *end; - int i; + int i = 0; + char temp[64]; /* Find the setting's cfg_name */ if (*ptr != '|') @@ -762,17 +772,30 @@ static int parse_setting(const char *wps_bufptr, end = strchr(ptr,'|'); if (!end) return WPS_ERROR_INVALID_PARAM; - - /* Find the setting */ - for (i=0; itype == WPS_TOKEN_TRANSLATEDSTRING) + { +#ifndef __PCTOOL__ + i = lang_english_to_id(temp); + if (i < 0) + return WPS_ERROR_INVALID_PARAM; +#endif + } + else + { + /* Find the setting */ + for (i=0; ivalue.i = i; diff --git a/apps/gui/skin_engine/skin_tokens.c b/apps/gui/skin_engine/skin_tokens.c index 94d8eb4dc..758a8c1b0 100644 --- a/apps/gui/skin_engine/skin_tokens.c +++ b/apps/gui/skin_engine/skin_tokens.c @@ -170,6 +170,9 @@ const char *get_token_value(struct gui_wps *gwps, case WPS_TOKEN_STRING: return (char*)token->value.data; + + case WPS_TOKEN_TRANSLATEDSTRING: + return (char*)P2STR(ID2P(token->value.i)); case WPS_TOKEN_TRACK_TIME_ELAPSED: format_time(buf, buf_size, diff --git a/apps/gui/skin_engine/skin_tokens.h b/apps/gui/skin_engine/skin_tokens.h index ad016047b..86425424d 100644 --- a/apps/gui/skin_engine/skin_tokens.h +++ b/apps/gui/skin_engine/skin_tokens.h @@ -32,6 +32,7 @@ enum wps_token_type { /* Markers */ WPS_TOKEN_CHARACTER, WPS_TOKEN_STRING, + WPS_TOKEN_TRANSLATEDSTRING, /* Alignment */ WPS_TOKEN_ALIGN_LEFT, diff --git a/apps/gui/skin_engine/wps_debug.c b/apps/gui/skin_engine/wps_debug.c index df96548e9..e06ce0021 100644 --- a/apps/gui/skin_engine/wps_debug.c +++ b/apps/gui/skin_engine/wps_debug.c @@ -76,6 +76,9 @@ static char *get_token_desc(struct wps_token *token, char *buf, snprintf(buf, bufsize, "String '%s'", (char*)token->value.data); break; + case WPS_TOKEN_TRANSLATEDSTRING: + snprintf(buf, bufsize, "String ID '%d'", token->value.i); + break; #ifdef HAVE_LCD_BITMAP case WPS_TOKEN_ALIGN_LEFT: diff --git a/apps/language.c b/apps/language.c index 7253ec275..73ed0fe39 100644 --- a/apps/language.c +++ b/apps/language.c @@ -98,3 +98,16 @@ int lang_load(const char *filename) close(fd); return retcode; } + +int lang_english_to_id(const char* english) +{ + int i; + unsigned char *ptr = (unsigned char *) language_builtin; + + for (i = 0; i < LANG_LAST_INDEX_IN_ARRAY; i++) { + if (!strcmp(ptr, english)) + return i; + ptr += strlen((char *)ptr) + 1; /* advance pointer to next string */ + } + return -1; +} diff --git a/apps/language.h b/apps/language.h index a35387cf4..06769a3dd 100644 --- a/apps/language.h +++ b/apps/language.h @@ -27,4 +27,7 @@ void lang_init(void); /* load a given language file */ int lang_load(const char *filename); +/* get the ID of an english string so it can be localised */ +int lang_english_to_id(const char* english); + #endif -- 2.11.4.GIT