Просмотр исходного кода

Merge pull request #274 from lemenkov/gettext_nonexisting_functions

Fix calls to Gettext nonexisting functions
Andreas Stenius 2 лет назад
Родитель
Сommit
55d93eb3d7
1 измененных файлов с 22 добавлено и 7 удалено
  1. 22 7
      src/i18n/po_generator.erl

+ 22 - 7
src/i18n/po_generator.erl

@@ -15,31 +15,46 @@
 %%
 %% API Functions
 %%
+-define(LANG_DIR, "lang").
+-define(POFILE, "gettext.po").
 generate_file(Lang,Items, Fuzzy) ->
     Gettext_App_Name = "tmp",
     GtxtDir = ".",
     io:format("Opening po file"),
-    gettext_compile:open_po_file(Gettext_App_Name, GtxtDir, Lang),
+    DefDir = filename:join([GtxtDir, ?LANG_DIR, Gettext_App_Name, Lang]),
+    Fname = filename:join([DefDir, ?POFILE]),
+    filelib:ensure_dir(Fname),
+    {ok,Fd} = file:open(Fname, [write]),
+    put(fd,Fd),
 
     gettext_compile:write_header(),
     io:format("Writing entries~n"),
     write_entries(Items),
     io:format("Writing fuzzy entries~n"),
     write_fuzzy_entries(Fuzzy),
-    gettext_compile:close_file().
+    file:close(Fd).
 
 %%
 %% Local Functions
 %%
+
+to_list(A) when is_atom(A)    -> atom_to_list(A);
+to_list(I) when is_integer(I) -> integer_to_list(I);
+to_list(B) when is_binary(B)  -> binary_to_list(B);
+to_list(L) when is_list(L)    -> L.
+
 write_entries(Items)->
     Fd = get(fd),
     F = fun({Id,Translation,Finfo}) ->
-                Fi = gettext_compile:fmt_fileinfo(Finfo),
+                Fun = fun({Fname,LineNo}, Acc) ->
+                    Fname ++ ":" ++ to_list(LineNo) ++ [$\s|Acc]
+                end,
+                Fi = lists:foldr(Fun,[],Finfo),
                 io:format(Fd, "~n#: ~s~n", [Fi]),
                 ok = file:write(Fd, "msgid \"\"\n"),
-                gettext_compile:write_pretty(Id),
+                gettext_compile:write_pretty(Id, Fd),
                 ok = file:write(Fd, "msgstr \"\"\n"),
-                gettext_compile:write_pretty(Translation)
+                gettext_compile:write_pretty(Translation, Fd)
         end,
     lists:foreach(F, Items).
 
@@ -49,9 +64,9 @@ write_fuzzy_entries(Items) ->
     F = fun({Id,Translation,_}) ->
                 ok = file:write(Fd, "#, fuzzy\n"),
                 ok = file:write(Fd, "msgid \"\"\n"),
-                gettext_compile:write_pretty(Id),
+                gettext_compile:write_pretty(Id, Fd),
                 ok = file:write(Fd, "msgstr \"\"\n"),
-                gettext_compile:write_pretty(Translation),
+                gettext_compile:write_pretty(Translation, Fd),
                 ok = file:write(Fd, "\n")
         end,
     lists:foreach(F, Items).