|
@@ -15,31 +15,46 @@
|
|
%%
|
|
%%
|
|
%% API Functions
|
|
%% API Functions
|
|
%%
|
|
%%
|
|
|
|
+-define(LANG_DIR, "lang").
|
|
|
|
+-define(POFILE, "gettext.po").
|
|
generate_file(Lang,Items, Fuzzy) ->
|
|
generate_file(Lang,Items, Fuzzy) ->
|
|
Gettext_App_Name = "tmp",
|
|
Gettext_App_Name = "tmp",
|
|
GtxtDir = ".",
|
|
GtxtDir = ".",
|
|
io:format("Opening po file"),
|
|
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(),
|
|
gettext_compile:write_header(),
|
|
io:format("Writing entries~n"),
|
|
io:format("Writing entries~n"),
|
|
write_entries(Items),
|
|
write_entries(Items),
|
|
io:format("Writing fuzzy entries~n"),
|
|
io:format("Writing fuzzy entries~n"),
|
|
write_fuzzy_entries(Fuzzy),
|
|
write_fuzzy_entries(Fuzzy),
|
|
- gettext_compile:close_file().
|
|
|
|
|
|
+ file:close(Fd).
|
|
|
|
|
|
%%
|
|
%%
|
|
%% Local Functions
|
|
%% 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)->
|
|
write_entries(Items)->
|
|
Fd = get(fd),
|
|
Fd = get(fd),
|
|
F = fun({Id,Translation,Finfo}) ->
|
|
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]),
|
|
io:format(Fd, "~n#: ~s~n", [Fi]),
|
|
ok = file:write(Fd, "msgid \"\"\n"),
|
|
ok = file:write(Fd, "msgid \"\"\n"),
|
|
- gettext_compile:write_pretty(Id),
|
|
|
|
|
|
+ gettext_compile:write_pretty(Id, Fd),
|
|
ok = file:write(Fd, "msgstr \"\"\n"),
|
|
ok = file:write(Fd, "msgstr \"\"\n"),
|
|
- gettext_compile:write_pretty(Translation)
|
|
|
|
|
|
+ gettext_compile:write_pretty(Translation, Fd)
|
|
end,
|
|
end,
|
|
lists:foreach(F, Items).
|
|
lists:foreach(F, Items).
|
|
|
|
|
|
@@ -49,9 +64,9 @@ write_fuzzy_entries(Items) ->
|
|
F = fun({Id,Translation,_}) ->
|
|
F = fun({Id,Translation,_}) ->
|
|
ok = file:write(Fd, "#, fuzzy\n"),
|
|
ok = file:write(Fd, "#, fuzzy\n"),
|
|
ok = file:write(Fd, "msgid \"\"\n"),
|
|
ok = file:write(Fd, "msgid \"\"\n"),
|
|
- gettext_compile:write_pretty(Id),
|
|
|
|
|
|
+ gettext_compile:write_pretty(Id, Fd),
|
|
ok = file:write(Fd, "msgstr \"\"\n"),
|
|
ok = file:write(Fd, "msgstr \"\"\n"),
|
|
- gettext_compile:write_pretty(Translation),
|
|
|
|
|
|
+ gettext_compile:write_pretty(Translation, Fd),
|
|
ok = file:write(Fd, "\n")
|
|
ok = file:write(Fd, "\n")
|
|
end,
|
|
end,
|
|
lists:foreach(F, Items).
|
|
lists:foreach(F, Items).
|