cedric pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=26b27319b42baa40acda3acbccdfedeed4dad838

commit 26b27319b42baa40acda3acbccdfedeed4dad838
Author: katpavalli <katpag...@samsung.com>
Date:   Thu Jun 11 10:40:32 2015 +0200

    edje: add po file support in edc translation.
    
    Summary:
       Implementation to support .po files in edc for translation
    
    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
       edje_cc -md . text.edc && gcc -o edje-text edje-text.c `pkg-config 
--libs --cflags ecore-evas edje evas ecore eo`
       ./edje-text
    
       1) Click On the text "Click here"
          The language gets changed.
    
    Reviewers: shilpasingh, cedric
    
    Reviewed By: shilpasingh, cedric
    
    Subscribers: cedric, rajeshps, govi, poornima.srinivasan
    
    Differential Revision: https://phab.enlightenment.org/D2573
    
    Signed-off-by: Cedric BAIL <ced...@osg.samsung.com>
---
 src/bin/edje/edje_cc_handlers.c        |  20 +++++----
 src/bin/edje/edje_cc_out.c             |  80 ++++++++++++++++++++++++++++++---
 src/examples/edje/en_IN/domain_name.mo | Bin 201 -> 0 bytes
 src/examples/edje/en_IN/domain_name.po |  11 +++++
 src/examples/edje/hi_IN/domain_name.mo | Bin 260 -> 0 bytes
 src/examples/edje/hi_IN/domain_name.po |  11 +++++
 src/examples/edje/text.edc             |  18 ++++----
 src/lib/edje/edje_load.c               |  11 ++++-
 src/lib/edje/edje_private.h            |   2 +-
 9 files changed, 127 insertions(+), 26 deletions(-)

diff --git a/src/bin/edje/edje_cc_handlers.c b/src/bin/edje/edje_cc_handlers.c
index 5b5d233..5239072 100644
--- a/src/bin/edje/edje_cc_handlers.c
+++ b/src/bin/edje/edje_cc_handlers.c
@@ -154,6 +154,8 @@ Eina_Bool current_group_inherit = EINA_FALSE;
 static Edje_Program *sequencing = NULL;
 static Eina_List *sequencing_lookups = NULL;
 
+Eina_List *po_files;
+
 struct _Edje_Cc_Handlers_Hierarchy_Info
 {  /* Struct that keeps globals value to impl hierarchy */
    Edje_Part_Collection_Directory_Entry *current_de;
@@ -3056,23 +3058,23 @@ st_collections_group_vibration_sample_source(void)
             ..
             file {
                 locale: "en_IN";
-                source: "domain_name.mo";
+                source: "domain_name.po";
             }
             file {
                 locale: "en_US";
-                source: "domain_name.mo";
+                source: "domain_name.po";
             }
         }
     @description
-        The file block defines the mo file.
+        The file block defines the po or mo file.
     @endblock
     @property
         name
     @parameters
         [locale name] 
     @effect
-        Used to include each mo file. The full path to the directory holding
-        the mo file can be defined later with edje_cc's "-md" option.
+        Used to include each po or mo file. The full path to the directory 
holding
+        the po or mo file can be defined later with edje_cc's "-md" option.
 
     @since 1.15
     @endproperty
@@ -3122,10 +3124,10 @@ st_collections_group_translation_file_locale(void)
     @property
         source
     @parameters
-        [mo file name]
+        [po file name or Mo file name]
     @effect
-        The mo source file name (Source should be a valid mo file.
-        Only mo files are supported now)
+        The po or mo source file name (Source should be a valid po or mo file.
+        Only po or mo files are supported now)
     @since 1.15
     @endproperty
  */
@@ -3134,7 +3136,7 @@ static void
 st_collections_group_translation_file_source(void)
 {
    Edje_Mo *mo_entry;
-
+   char *mo_path_str;
    check_arg_count(1);
 
    if (!edje_file->mo_dir->mo_entries)
diff --git a/src/bin/edje/edje_cc_out.c b/src/bin/edje/edje_cc_out.c
index f755254..485aa8c 100755
--- a/src/bin/edje/edje_cc_out.c
+++ b/src/bin/edje/edje_cc_out.c
@@ -169,6 +169,8 @@ struct _Mo_Write
 {
    Eet_File *ef;
    Edje_Mo *mo_entry;
+   char *mo_path;
+   Ecore_Exe *exe;
    char *errstr;
 };
 
@@ -205,6 +207,8 @@ static int pending_threads = 0;
 
 static void data_process_string(Edje_Part_Collection *pc, const char *prefix, 
char *s, void (*func)(Edje_Part_Collection *pc, char *name, char* ptr, int 
len));
 
+extern Eina_List *po_files;
+
 Edje_File *edje_file = NULL;
 Eina_List *edje_collections = NULL;
 Eina_Hash *edje_collections_lookup = NULL;
@@ -1232,6 +1236,8 @@ data_thread_mo(void *data, Ecore_Thread *thread 
EINA_UNUSED)
          eina_file_map_free(f, m);
      }
    eina_file_close(f);
+   if (mw->mo_path)
+     ecore_file_remove(mo_path);
 
    INF("Wrote %9i bytes (%4iKb) for \"%s\" %s mo entry \"%s\"",
           bytes, (bytes + 512) / 1024, moid_str, "RAW PCM", 
mw->mo_entry->locale);
@@ -1249,9 +1255,38 @@ data_thread_mo_end(void *data, Ecore_Thread *thread 
EINA_UNUSED)
        error_and_abort(mw->ef, mw->errstr);
        free(mw->errstr);
      }
+   if (mw->mo_path)
+     free(mw->mo_path);
    free(mw);
 }
 
+Eina_Bool
+_exe_del_cb(void *data EINA_UNUSED, int evtype EINA_UNUSED, void *evinfo)
+{
+   Mo_Write *mw = data;
+   Ecore_Exe_Event_Del *ev = evinfo;
+   if (!ev->exe) return ECORE_CALLBACK_RENEW;
+   if (ecore_exe_data_get(ev->exe) != mw) return ECORE_CALLBACK_RENEW;
+   if (ev->exit_code != 0)
+     {
+        error_and_abort(mw->ef, "Creation of .mo from .po failed.");
+        return ECORE_CALLBACK_CANCEL;
+     }
+   if (ecore_file_exists(mw->mo_path))
+     {
+        if (threads)
+          ecore_thread_run(data_thread_mo, data_thread_mo_end, NULL, mw);
+        else
+          {
+             data_thread_mo(mw, NULL);
+             data_thread_mo_end(mw, NULL);
+          }
+     }
+   else
+     return ECORE_CALLBACK_RENEW;
+   if (pending_threads <= 0) ecore_main_loop_quit();
+   return ECORE_CALLBACK_CANCEL;
+}
 
 static void
 data_write_mo(Eet_File *ef, int *mo_num)
@@ -1259,24 +1294,57 @@ data_write_mo(Eet_File *ef, int *mo_num)
    if ((edje_file) && (edje_file->mo_dir))
      {
         int i;
+        char *po_entry;
+        char *sub_str;
+        char buf[PATH_MAX];
+        Eina_List *ll;
+        char *dir_path = NULL;
+        char mo_path[PATH_MAX];
+        char po_path[PATH_MAX];
 
         for (i = 0; i < (int)edje_file->mo_dir->mo_entries_count; i++)
           {
              Mo_Write *mw;
-
              mw = calloc(1, sizeof(Mo_Write));
              if (!mw) continue;
              mw->ef = ef;
              mw->mo_entry = &edje_file->mo_dir->mo_entries[i];
              *mo_num += 1;
              pending_threads++;
-             if (threads)
-               ecore_thread_run(data_thread_mo, data_thread_mo_end, NULL, mw);
-             else
+
+             po_entry = strdup(mw->mo_entry->mo_src);
+             sub_str = strstr(mw->mo_entry->mo_src, ".po");
+
+             if (sub_str)
                {
-                  data_thread_mo(mw, NULL);
-                  data_thread_mo_end(mw, NULL);
+                  sub_str[1] = 'm';
+                  EINA_LIST_FOREACH(mo_dirs, ll, dir_path)
+                    {
+                       snprintf((char *)mo_path, sizeof(mo_path), "%s/%s/%s", 
dir_path, mw->mo_entry->locale, mw->mo_entry->mo_src);
+                       snprintf((char *)po_path, sizeof(po_path), "%s/%s/%s", 
dir_path, mw->mo_entry->locale, po_entry);
+                       if (ecore_file_exists(po_path))
+                         {
+                            snprintf(buf, sizeof(buf), "msgfmt -o %s %s", 
mo_path, po_path);
+                            mw->mo_path = strdup(mo_path);
+                            mw->exe = ecore_exe_run(buf, mw);
+                            ecore_event_handler_add(ECORE_EXE_EVENT_DEL,
+                                                       _exe_del_cb, mw);
+                         }
+                       else
+                         error_and_abort(mw->ef, "Invalid .po file.");
+                    }
+               }
+             else
+               { 
+                  if (threads)
+                    ecore_thread_run(data_thread_mo, data_thread_mo_end, NULL, 
mw);
+                  else
+                    {
+                       data_thread_mo(mw, NULL);
+                       data_thread_mo_end(mw, NULL);
+                    }
                }
+             free(po_entry);
           }
      }
 }
diff --git a/src/examples/edje/en_IN/domain_name.mo 
b/src/examples/edje/en_IN/domain_name.mo
deleted file mode 100644
index 0c1b2fc..0000000
Binary files a/src/examples/edje/en_IN/domain_name.mo and /dev/null differ
diff --git a/src/examples/edje/en_IN/domain_name.po 
b/src/examples/edje/en_IN/domain_name.po
new file mode 100644
index 0000000..f461123
--- /dev/null
+++ b/src/examples/edje/en_IN/domain_name.po
@@ -0,0 +1,11 @@
+msgid "LOADING"
+msgstr "Loading..."
+
+msgid "LANG"
+msgstr "Language English"
+
+msgid "SYSTEM LANGUAGE"
+msgstr "System Language"
+
+msgid "CHANGED"
+msgstr "Changed"
diff --git a/src/examples/edje/hi_IN/domain_name.mo 
b/src/examples/edje/hi_IN/domain_name.mo
deleted file mode 100644
index 3901b8c..0000000
Binary files a/src/examples/edje/hi_IN/domain_name.mo and /dev/null differ
diff --git a/src/examples/edje/hi_IN/domain_name.po 
b/src/examples/edje/hi_IN/domain_name.po
new file mode 100644
index 0000000..809cf6f
--- /dev/null
+++ b/src/examples/edje/hi_IN/domain_name.po
@@ -0,0 +1,11 @@
+msgid "LOADING"
+msgstr "लोड हो रहा है..."
+
+msgid "LANG"
+msgstr "भाषा हिन्दी"
+
+msgid "SYSTEM LANGUAGE"
+msgstr "सिस्टम भाषा"
+
+msgid "CHANGED"
+msgstr "बदल"
diff --git a/src/examples/edje/text.edc b/src/examples/edje/text.edc
index ed0548d..75fcaed 100644
--- a/src/examples/edje/text.edc
+++ b/src/examples/edje/text.edc
@@ -21,15 +21,15 @@ collections {
       translation {
          file {
             locale: en_IN;
-            source: domain_name.mo; /* Can be either .po file or .mo file */
+            source: domain_name.po; /* Can be either .po file or .mo file*/
          }
          file {
             locale: hi_IN;
-            source: domain_name.mo;
+            source: domain_name.po;
          }
          file {
             locale: ta_IN;
-            source: domain_name.mo;
+            source: domain_name.po;
          }
       }
       styles {
@@ -144,11 +144,11 @@ collections {
       translation {
          file {
             locale: en_IN;
-            source: domain_name.mo;
+            source: domain_name.po;
          }
          file {
             locale: hi_IN;
-            source: domain_name.mo;
+            source: domain_name.po;
          }
          file {
             locale: ta_IN;
@@ -267,11 +267,11 @@ collections {
       translation {
          file {
             locale: en_IN;
-            source: domain_name.mo;
+            source: domain_name.po;
          }
          file {
             locale: hi_IN;
-            source: domain_name.mo;
+            source: domain_name.po;
          }
          file {
             locale: ta_IN;
@@ -390,11 +390,11 @@ collections {
       translation {
          file {
             locale: en_IN;
-            source: domain_name.mo;
+            source: domain_name.po;
          }
          file {
             locale: hi_IN;
-            source: domain_name.mo;
+            source: domain_name.po;
          }
          file {
             locale: ta_IN;
diff --git a/src/lib/edje/edje_load.c b/src/lib/edje/edje_load.c
index add6a1a..0457c81 100644
--- a/src/lib/edje/edje_load.c
+++ b/src/lib/edje/edje_load.c
@@ -84,6 +84,8 @@ _edje_extract_mo_files(Edje *ed)
         Edje_Mo *mo_entry;
         char out[PATH_MAX];
         char outdir[PATH_MAX];
+        char *sub_str;
+        char *mo_src;
 
         mo_entry = &ed->file->mo_dir->mo_entries[i];
 
@@ -101,8 +103,14 @@ _edje_extract_mo_files(Edje *ed)
                       "%s/edje/%s/LC_MESSAGES",
                       cache_path, mo_entry->locale);
              ecore_file_mkpath(outdir);
+             mo_src = strdup(mo_entry->mo_src);
+             sub_str = strstr(mo_src, ".po");
+
+             if (sub_str)
+               sub_str[1] = 'm';
+
              snprintf(out, sizeof(out), "%s/%s-%s",
-                      outdir, ed->file->fid, mo_entry->mo_src);
+                      outdir, ed->file->fid, mo_src);
              if (ecore_file_exists(out))
                {
                   if (ed->file->mtime > ecore_file_mod_time(out))
@@ -122,6 +130,7 @@ _edje_extract_mo_files(Edje *ed)
                   else
                     ERR("Could not open for writing mo: %s: %s", out, 
strerror(errno));
                }
+             free(mo_src);
           }
 
         eina_strbuf_reset(mo_id_str);
diff --git a/src/lib/edje/edje_private.h b/src/lib/edje/edje_private.h
index d888c36..3b41699 100644
--- a/src/lib/edje/edje_private.h
+++ b/src/lib/edje/edje_private.h
@@ -695,7 +695,7 @@ struct _Edje_Sound_Directory
 struct _Edje_Mo /*Mo Sample*/
 {
    const char *locale; /* the nominal name of the Mo */
-   const char *mo_src;  /* Mo source file */
+   char *mo_src;  /* Mo source file */
    int   id; /* the id no. of the Mo file */
 };
 

-- 


Reply via email to