summaryrefslogtreecommitdiff
path: root/src/bin
diff options
context:
space:
mode:
authorkatpavalli <katpaga.a@samsung.com>2015-05-13 18:08:04 +0200
committerCedric BAIL <cedric@osg.samsung.com>2015-05-14 18:41:47 +0200
commitdca95fb45af216068b5476f7110639cb3715b96b (patch)
tree49691183f3c708bebf663a3f8a34d00028ae6f5d /src/bin
parenta312e304bf181777aa8190f4281ebdac49a827a5 (diff)
edje: support translation on static strings in edc.
Summary: Internationalisation of the static text specified as part of the edc is implemented. Problem: Static text when specified in the edc, remains unchanged when the system language is changed. Solution: Language support is provided even for the static strings in the edc. Test Plan: Test code to test this implementation is done as part of efl/src/examples/edje/edje-text.c and efl/src/examples/edje/text.edc Compile the code with the below command edje_cc -md <dir path>/efl/src/examples/edje/ text.edc && gcc -o edje-text edje-text.c `pkg-config --libs --cflags ecore-evas edje evas ecore` ./edje-text 1) change the language of the system using the command export LANGUAGE=hi ./edje.text Not the text Loading gets displayed in hindi language 2) change the language of the system using the command export LANGUAGE=ta ./edje.text Not the text Loading gets displayed in tamil language 3) change the language of the system using the command export LANGUAGE=en ./edje.text Not the text Loading gets displayed in english language As the number of .mo files in the /edje folder can be increased, those many languages can be supported Reviewers: cedric, shilpasingh Reviewed By: shilpasingh Subscribers: cedric, rajeshps, govi, poornima.srinivasan Differential Revision: https://phab.enlightenment.org/D2336 Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
Diffstat (limited to 'src/bin')
-rw-r--r--src/bin/edje/edje_cc.c7
-rw-r--r--src/bin/edje/edje_cc.h1
-rw-r--r--src/bin/edje/edje_cc_handlers.c149
-rwxr-xr-xsrc/bin/edje/edje_cc_out.c114
4 files changed, 271 insertions, 0 deletions
diff --git a/src/bin/edje/edje_cc.c b/src/bin/edje/edje_cc.c
index 45b4105b43..690ba23341 100644
--- a/src/bin/edje/edje_cc.c
+++ b/src/bin/edje/edje_cc.c
@@ -13,6 +13,7 @@ static void main_help(void);
13 13
14Eina_Prefix *pfx = NULL; 14Eina_Prefix *pfx = NULL;
15Eina_List *snd_dirs = NULL; 15Eina_List *snd_dirs = NULL;
16Eina_List *mo_dirs = NULL;
16Eina_List *vibration_dirs = NULL; 17Eina_List *vibration_dirs = NULL;
17Eina_List *img_dirs = NULL; 18Eina_List *img_dirs = NULL;
18Eina_List *fnt_dirs = NULL; 19Eina_List *fnt_dirs = NULL;
@@ -98,6 +99,7 @@ main_help(void)
98 "-sd sound/directory Add a directory to look in for relative path sounds samples\n" 99 "-sd sound/directory Add a directory to look in for relative path sounds samples\n"
99 "-vd vibration/directory Add a directory to look in for relative path vibration samples\n" 100 "-vd vibration/directory Add a directory to look in for relative path vibration samples\n"
100 "-dd data/directory Add a directory to look in for relative path data.file entries\n" 101 "-dd data/directory Add a directory to look in for relative path data.file entries\n"
102 "-md mo/directory Add a directory to look in for relative path mo files\n"
101 "-td temp/directory Directory to store temporary files\n" 103 "-td temp/directory Directory to store temporary files\n"
102 "-l license Specify the license of a theme (file with license text)\n" 104 "-l license Specify the license of a theme (file with license text)\n"
103 "-a authors Specify AUTHORS (file with list of authors)\n" 105 "-a authors Specify AUTHORS (file with list of authors)\n"
@@ -210,6 +212,11 @@ main(int argc, char **argv)
210 i++; 212 i++;
211 snd_dirs = eina_list_append(snd_dirs, argv[i]); 213 snd_dirs = eina_list_append(snd_dirs, argv[i]);
212 } 214 }
215 else if ((!strcmp(argv[i], "-md") || !strcmp(argv[i], "--mo_dir")) && (i < (argc - 1)))
216 {
217 i++;
218 mo_dirs = eina_list_append(mo_dirs, argv[i]);
219 }
213 else if ((!strcmp(argv[i], "-vd") || !strcmp(argv[i], "--vibration_dir")) && (i < (argc - 1))) 220 else if ((!strcmp(argv[i], "-vd") || !strcmp(argv[i], "--vibration_dir")) && (i < (argc - 1)))
214 { 221 {
215 i++; 222 i++;
diff --git a/src/bin/edje/edje_cc.h b/src/bin/edje/edje_cc.h
index 5efb076035..6b1e16c24a 100644
--- a/src/bin/edje/edje_cc.h
+++ b/src/bin/edje/edje_cc.h
@@ -253,6 +253,7 @@ extern Eina_List *ext_dirs;
253extern Eina_List *img_dirs; 253extern Eina_List *img_dirs;
254extern Eina_List *fnt_dirs; 254extern Eina_List *fnt_dirs;
255extern Eina_List *snd_dirs; 255extern Eina_List *snd_dirs;
256extern Eina_List *mo_dirs;
256extern Eina_List *vibration_dirs; 257extern Eina_List *vibration_dirs;
257extern Eina_List *data_dirs; 258extern Eina_List *data_dirs;
258extern char *file_in; 259extern char *file_in;
diff --git a/src/bin/edje/edje_cc_handlers.c b/src/bin/edje/edje_cc_handlers.c
index 78d11bb1c9..21751d30ba 100644
--- a/src/bin/edje/edje_cc_handlers.c
+++ b/src/bin/edje/edje_cc_handlers.c
@@ -343,6 +343,7 @@ static void st_collections_group_parts_part_description_color(void);
343static void st_collections_group_parts_part_description_color2(void); 343static void st_collections_group_parts_part_description_color2(void);
344static void st_collections_group_parts_part_description_color3(void); 344static void st_collections_group_parts_part_description_color3(void);
345static void st_collections_group_parts_part_description_text_text(void); 345static void st_collections_group_parts_part_description_text_text(void);
346static void st_collections_group_parts_part_description_text_domain(void);
346static void st_collections_group_parts_part_description_text_text_class(void); 347static void st_collections_group_parts_part_description_text_text_class(void);
347static void st_collections_group_parts_part_description_text_font(void); 348static void st_collections_group_parts_part_description_text_font(void);
348static void st_collections_group_parts_part_description_text_style(void); 349static void st_collections_group_parts_part_description_text_style(void);
@@ -460,6 +461,8 @@ static void st_collections_group_sound_tone(void);
460static void st_collections_group_vibration_sample_name(void); 461static void st_collections_group_vibration_sample_name(void);
461static void st_collections_group_vibration_sample_source(void); 462static void st_collections_group_vibration_sample_source(void);
462 463
464static void st_collections_group_translation_file_locale(void);
465static void st_collections_group_translation_file_source(void);
463#ifdef HAVE_EPHYSICS 466#ifdef HAVE_EPHYSICS
464static void st_collections_group_physics_world_gravity(void); 467static void st_collections_group_physics_world_gravity(void);
465static void st_collections_group_physics_world_rate(void); 468static void st_collections_group_physics_world_rate(void);
@@ -620,6 +623,10 @@ New_Statement_Handler statement_handlers[] =
620 {"collections.font", st_fonts_font}, /* dup */ 623 {"collections.font", st_fonts_font}, /* dup */
621 FONT_STYLE_CC_STATEMENTS("collections.") 624 FONT_STYLE_CC_STATEMENTS("collections.")
622 {"collections.base_scale", st_collections_base_scale}, 625 {"collections.base_scale", st_collections_base_scale},
626 {"collections.translation.file.locale", st_collections_group_translation_file_locale},
627 {"collections.translation.file.source", st_collections_group_translation_file_source},
628 {"collections.group.translation.file.locale", st_collections_group_translation_file_locale},
629 {"collections.group.translation.file.source", st_collections_group_translation_file_source},
623 630
624 {"collections.sounds.sample.name", st_collections_group_sound_sample_name}, 631 {"collections.sounds.sample.name", st_collections_group_sound_sample_name},
625 {"collections.sounds.sample.source", st_collections_group_sound_sample_source}, 632 {"collections.sounds.sample.source", st_collections_group_sound_sample_source},
@@ -783,6 +790,7 @@ New_Statement_Handler statement_handlers[] =
783 {"collections.group.parts.part.description.color2", st_collections_group_parts_part_description_color2}, 790 {"collections.group.parts.part.description.color2", st_collections_group_parts_part_description_color2},
784 {"collections.group.parts.part.description.color3", st_collections_group_parts_part_description_color3}, 791 {"collections.group.parts.part.description.color3", st_collections_group_parts_part_description_color3},
785 {"collections.group.parts.part.description.text.text", st_collections_group_parts_part_description_text_text}, 792 {"collections.group.parts.part.description.text.text", st_collections_group_parts_part_description_text_text},
793 {"collections.group.parts.part.description.text.domain", st_collections_group_parts_part_description_text_domain},
786 {"collections.group.parts.part.description.text.text_class", st_collections_group_parts_part_description_text_text_class}, 794 {"collections.group.parts.part.description.text.text_class", st_collections_group_parts_part_description_text_text_class},
787 {"collections.group.parts.part.description.text.font", st_collections_group_parts_part_description_text_font}, 795 {"collections.group.parts.part.description.text.font", st_collections_group_parts_part_description_text_font},
788 {"collections.group.parts.part.description.text.style", st_collections_group_parts_part_description_text_style}, 796 {"collections.group.parts.part.description.text.style", st_collections_group_parts_part_description_text_style},
@@ -1095,6 +1103,10 @@ New_Object_Handler object_handlers[] =
1095 {"collections.sounds", NULL}, 1103 {"collections.sounds", NULL},
1096 {"collections.group.sounds", NULL}, /* dup */ 1104 {"collections.group.sounds", NULL}, /* dup */
1097 {"collections.sounds.sample", NULL}, 1105 {"collections.sounds.sample", NULL},
1106 {"collections.translation", NULL},
1107 {"collections.translation.file", NULL},
1108 {"collections.group.translation", NULL},/*dup*/
1109 {"collections.group.translation.file", NULL},/*dup*/
1098 {"collections.group.sounds.sample", NULL}, /* dup */ 1110 {"collections.group.sounds.sample", NULL}, /* dup */
1099 {"collections.vibrations", NULL}, 1111 {"collections.vibrations", NULL},
1100 {"collections.group.vibrations", NULL}, /* dup */ 1112 {"collections.group.vibrations", NULL}, /* dup */
@@ -3032,6 +3044,109 @@ st_collections_group_vibration_sample_source(void)
3032 check_arg_count(1); 3044 check_arg_count(1);
3033} 3045}
3034 3046
3047/** @edcsubsection{collections_translation_file,
3048 * translation.file} */
3049
3050/**
3051 @page edcref
3052 @block
3053 file
3054 @context
3055 translation {
3056 ..
3057 file {
3058 locale: "en_IN";
3059 source: "domain_name.mo";
3060 }
3061 file {
3062 locale: "en_US";
3063 source: "domain_name.mo";
3064 }
3065 }
3066 @description
3067 The file block defines the mo file.
3068 @endblock
3069 @property
3070 name
3071 @parameters
3072 [locale name]
3073 @effect
3074 Used to include each mo file. The full path to the directory holding
3075 the mo file can be defined later with edje_cc's "-md" option.
3076
3077 @since 1.15
3078 @endproperty
3079 */
3080static void
3081st_collections_group_translation_file_locale(void)
3082{
3083 Edje_Mo *mo_entry;
3084 const char *tmp;
3085 unsigned int i;
3086
3087 check_arg_count(1);
3088
3089 if (!edje_file->mo_dir)
3090 edje_file->mo_dir = mem_alloc(SZ(Edje_Mo_Directory));
3091
3092 tmp = parse_str(0);
3093
3094 for (i = 0; i < edje_file->mo_dir->mo_entries_count; i++)
3095 {
3096 if (!strcmp(edje_file->mo_dir->mo_entries[i].locale, tmp))
3097 {
3098 free((char *)tmp);
3099 return;
3100 }
3101 }
3102
3103 edje_file->mo_dir->mo_entries_count++;
3104 mo_entry = realloc(edje_file->mo_dir->mo_entries, sizeof(Edje_Mo) * edje_file->mo_dir->mo_entries_count);
3105
3106 if (!mo_entry)
3107 {
3108 ERR("No enough memory.");
3109 exit(-1);
3110 }
3111 edje_file->mo_dir->mo_entries = mo_entry;
3112
3113 mo_entry = edje_file->mo_dir->mo_entries + edje_file->mo_dir->mo_entries_count - 1;
3114 memset(mo_entry, 0, sizeof (Edje_Mo));
3115
3116 mo_entry->locale = tmp;
3117 mo_entry->id = edje_file->mo_dir->mo_entries_count - 1;
3118}
3119
3120/**
3121 @page edcref
3122 @property
3123 source
3124 @parameters
3125 [mo file name]
3126 @effect
3127 The mo source file name (Source should be a valid mo file.
3128 Only mo files are supported now)
3129 @since 1.15
3130 @endproperty
3131 */
3132
3133static void
3134st_collections_group_translation_file_source(void)
3135{
3136 Edje_Mo *mo_entry;
3137
3138 check_arg_count(1);
3139
3140 if (!edje_file->mo_dir->mo_entries)
3141 {
3142 ERR("Invalid mo source definition.");
3143 exit(-1);
3144 }
3145
3146 mo_entry = edje_file->mo_dir->mo_entries + edje_file->mo_dir->mo_entries_count - 1;
3147 mo_entry->mo_src = parse_str(0);
3148}
3149
3035static void 3150static void
3036_link_combine(void) 3151_link_combine(void)
3037{ 3152{
@@ -6540,6 +6655,7 @@ st_collections_group_parts_part_description_inherit(void)
6540 ted->text = tparent->text; 6655 ted->text = tparent->text;
6541 6656
6542 ted->text.text.str = STRDUP(ted->text.text.str); 6657 ted->text.text.str = STRDUP(ted->text.text.str);
6658 ted->text.domain = STRDUP(ted->text.domain);
6543 ted->text.text_class = STRDUP(ted->text.text_class); 6659 ted->text.text_class = STRDUP(ted->text.text_class);
6544 ted->text.font.str = STRDUP(ted->text.font.str); 6660 ted->text.font.str = STRDUP(ted->text.font.str);
6545 ted->text.filter.str = STRDUP(ted->text.filter.str); 6661 ted->text.filter.str = STRDUP(ted->text.filter.str);
@@ -8247,6 +8363,7 @@ st_collections_group_parts_part_description_fill_size_offset(void)
8247 .. 8363 ..
8248 text { 8364 text {
8249 text: "some string of text to display"; 8365 text: "some string of text to display";
8366 domain: "domain_name";
8250 font: "font_name"; 8367 font: "font_name";
8251 size: SIZE; 8368 size: SIZE;
8252 text_class: "class_name"; 8369 text_class: "class_name";
@@ -8308,6 +8425,38 @@ st_collections_group_parts_part_description_text_text(void)
8308 ed->text.text.str = str; 8425 ed->text.text.str = str;
8309} 8426}
8310 8427
8428/** @edcsubsection{collections_group_parts_description_domain,
8429 * Group.Parts.Part.Description.Domain} */
8430
8431/**
8432 @page edcref
8433
8434 @property
8435 domain
8436 @parameters
8437 [domain name]
8438 @effect
8439 This is the domain name of the .mo file which has to be checked
8440 for translation.
8441 @endproperty
8442*/
8443static void
8444st_collections_group_parts_part_description_text_domain(void)
8445{
8446 Edje_Part_Description_Text *ed;
8447
8448 if ((current_part->type != EDJE_PART_TYPE_TEXT) &&
8449 (current_part->type != EDJE_PART_TYPE_TEXTBLOCK))
8450 {
8451 ERR("parse error %s:%i. text attributes in non-TEXT part.",
8452 file_in, line - 1);
8453 exit(-1);
8454 }
8455
8456 ed = (Edje_Part_Description_Text*) current_desc;
8457
8458 ed->text.domain = parse_str(0);
8459}
8311/** 8460/**
8312 @page edcref 8461 @page edcref
8313 8462
diff --git a/src/bin/edje/edje_cc_out.c b/src/bin/edje/edje_cc_out.c
index e1627070d3..95798fb5b0 100755
--- a/src/bin/edje/edje_cc_out.c
+++ b/src/bin/edje/edje_cc_out.c
@@ -116,6 +116,7 @@ typedef struct _Head_Write Head_Write;
116typedef struct _Fonts_Write Fonts_Write; 116typedef struct _Fonts_Write Fonts_Write;
117typedef struct _Image_Write Image_Write; 117typedef struct _Image_Write Image_Write;
118typedef struct _Sound_Write Sound_Write; 118typedef struct _Sound_Write Sound_Write;
119typedef struct _Mo_Write Mo_Write;
119typedef struct _Vibration_Write Vibration_Write; 120typedef struct _Vibration_Write Vibration_Write;
120typedef struct _Group_Write Group_Write; 121typedef struct _Group_Write Group_Write;
121typedef struct _License_Write License_Write; 122typedef struct _License_Write License_Write;
@@ -164,6 +165,13 @@ struct _Sound_Write
164 int i; 165 int i;
165}; 166};
166 167
168struct _Mo_Write
169{
170 Eet_File *ef;
171 Edje_Mo *mo_entry;
172 char *errstr;
173};
174
167struct _Vibration_Write 175struct _Vibration_Write
168{ 176{
169 Eet_File *ef; 177 Eet_File *ef;
@@ -1170,6 +1178,109 @@ data_write_sounds(Eet_File *ef, int *sound_num)
1170} 1178}
1171 1179
1172static void 1180static void
1181data_thread_mo(void *data, Ecore_Thread *thread EINA_UNUSED)
1182{
1183 Mo_Write *mw = data;
1184 char buf[PATH_MAX];
1185 Eina_List *ll;
1186
1187 char *dir_path = NULL;
1188 char mo_path[PATH_MAX];
1189 char moid_str[50];
1190 Eina_File *f = NULL;
1191 void *m = NULL;
1192 int bytes = 0;
1193
1194 // Search the mo file in all the -md ( mo directory )
1195 EINA_LIST_FOREACH(mo_dirs, ll, dir_path)
1196 {
1197 snprintf((char *)mo_path, sizeof(mo_path), "%s/%s/%s", dir_path, mw->mo_entry->locale, mw->mo_entry->mo_src);
1198 f = eina_file_open(mo_path, 0);
1199 if (f) break;
1200 }
1201 if (!f)
1202 {
1203 snprintf((char *)mo_path, sizeof(mo_path), "%s", mw->mo_entry->mo_src);
1204 f = eina_file_open(mo_path, 0);
1205 }
1206
1207 if (f) using_file(mo_path, 'S');
1208
1209 if (!f)
1210 {
1211 snprintf(buf, sizeof(buf), "Unable to load mo data of: %s", mo_path);
1212 ERR("%s", buf);
1213 mw->errstr = strdup(buf);
1214 exit(-1);
1215 }
1216
1217 snprintf(moid_str, sizeof(moid_str), "edje/mo/%i/%s/LC_MESSAGES", mw->mo_entry->id, mw->mo_entry->locale);
1218 m = eina_file_map_all(f, EINA_FILE_WILLNEED);
1219 if (m)
1220 {
1221 bytes = eet_write(mw->ef, moid_str, m, eina_file_size_get(f), EET_COMPRESSION_NONE);
1222 if (eina_file_map_faulted(f, m))
1223 {
1224 snprintf(buf, sizeof(buf), "File access error when reading '%s'",
1225 eina_file_filename_get(f));
1226 ERR("%s", buf);
1227 mw->errstr = strdup(buf);
1228 eina_file_close(f);
1229 exit(-1);
1230 }
1231 eina_file_map_free(f, m);
1232 }
1233 eina_file_close(f);
1234
1235 INF("Wrote %9i bytes (%4iKb) for \"%s\" %s mo entry \"%s\"",
1236 bytes, (bytes + 512) / 1024, moid_str, "RAW PCM", mw->mo_entry->locale);
1237
1238}
1239
1240static void
1241data_thread_mo_end(void *data, Ecore_Thread *thread EINA_UNUSED)
1242{
1243 Mo_Write *mw = data;
1244 pending_threads--;
1245 if (pending_threads <= 0) ecore_main_loop_quit();
1246 if (mw->errstr)
1247 {
1248 error_and_abort(mw->ef, mw->errstr);
1249 free(mw->errstr);
1250 }
1251 free(mw);
1252}
1253
1254
1255static void
1256data_write_mo(Eet_File *ef, int *mo_num)
1257{
1258 if ((edje_file) && (edje_file->mo_dir))
1259 {
1260 int i;
1261
1262 for (i = 0; i < (int)edje_file->mo_dir->mo_entries_count; i++)
1263 {
1264 Mo_Write *mw;
1265
1266 mw = calloc(1, sizeof(Mo_Write));
1267 if (!mw) continue;
1268 mw->ef = ef;
1269 mw->mo_entry = &edje_file->mo_dir->mo_entries[i];
1270 *mo_num += 1;
1271 pending_threads++;
1272 if (threads)
1273 ecore_thread_run(data_thread_mo, data_thread_mo_end, NULL, mw);
1274 else
1275 {
1276 data_thread_mo(mw, NULL);
1277 data_thread_mo_end(mw, NULL);
1278 }
1279 }
1280 }
1281}
1282
1283static void
1173data_thread_vibrations(void *data, Ecore_Thread *thread EINA_UNUSED) 1284data_thread_vibrations(void *data, Ecore_Thread *thread EINA_UNUSED)
1174{ 1285{
1175 Vibration_Write *vw = data; 1286 Vibration_Write *vw = data;
@@ -1986,6 +2097,7 @@ data_write(void)
1986 Eet_Error err; 2097 Eet_Error err;
1987 int image_num = 0; 2098 int image_num = 0;
1988 int sound_num = 0; 2099 int sound_num = 0;
2100 int mo_num = 0;
1989 int vibration_num = 0; 2101 int vibration_num = 0;
1990 int font_num = 0; 2102 int font_num = 0;
1991 int collection_num = 0; 2103 int collection_num = 0;
@@ -2047,6 +2159,8 @@ data_write(void)
2047 INF("fonts: %3.5f", ecore_time_get() - t); t = ecore_time_get(); 2159 INF("fonts: %3.5f", ecore_time_get() - t); t = ecore_time_get();
2048 data_write_sounds(ef, &sound_num); 2160 data_write_sounds(ef, &sound_num);
2049 INF("sounds: %3.5f", ecore_time_get() - t); t = ecore_time_get(); 2161 INF("sounds: %3.5f", ecore_time_get() - t); t = ecore_time_get();
2162 data_write_mo(ef, &mo_num);
2163 INF("mo: %3.5f", ecore_time_get() - t); t = ecore_time_get();
2050 data_write_vibrations(ef, &vibration_num); 2164 data_write_vibrations(ef, &vibration_num);
2051 INF("vibrations: %3.5f", ecore_time_get() - t); t = ecore_time_get(); 2165 INF("vibrations: %3.5f", ecore_time_get() - t); t = ecore_time_get();
2052 data_write_license(ef); 2166 data_write_license(ef);