Browse files

Fix utf be to le.

  • Loading branch information...
1 parent bd2c5d0 commit c40549ebc062f77c7e6c09ded02b9a0734d4d1bd @arcusfelis arcusfelis committed Sep 24, 2011
Showing with 53 additions and 6 deletions.
  1. +6 −1 include/l10n_meta.hrl
  2. +45 −3 src/l10n_expand.erl
  3. +1 −1 src/l10n_sup.erl
  4. +1 −1 src/l10n_utils.erl
View
7 include/l10n_meta.hrl
@@ -49,6 +49,10 @@
-define(L10N_RELOADER, list_to_atom(?MODULE_STRING ++ "_reloader")).
-endif.
+-ifndef(L10N_SUP).
+-define(L10N_SUP, list_to_atom(?MODULE_STRING ++ "_sup")).
+-endif.
+
-ifndef(L10N_TABLE).
-define(L10N_TABLE, ?MODULE).
-endif.
@@ -107,6 +111,7 @@ get_path(Type, Locale) ->
get_name('domain') -> ?MODULE;
get_name('table') -> ?L10N_TABLE;
get_name('reloader') -> ?L10N_RELOADER;
+get_name('supervisor') -> ?L10N_SUP;
get_name('server') -> ?L10N_SERVER.
%% @doc Get the name of l10n_store_server with locale=L.
@@ -144,7 +149,7 @@ format(Id, Params) ->
format(H, Id, Params).
format(H, Id, Params) ->
- Fmt = search(H, 5),
+ Fmt = search(H, Id, 5),
i18n_message:format(Fmt, Params).
-endif.
View
48 src/l10n_expand.erl
@@ -1,6 +1,48 @@
-module(l10n_expand).
-
-export([parse_transform/2]).
-parse_transform(AST, Options) ->
- ct_expand:parse_transform(AST, Options).
+-import(ct_expand, [function/4]).
+
+in(H, [H|_T]) -> true;
+in(X, [_H|T]) -> in(X, T);
+in(_X, []) -> false.
+
+parse_transform(Forms, Options) ->
+ try
+ Info = erl_syntax_lib:analyze_forms(Forms),
+ {'attributes', AttrList} = lists:keyfind('attributes', 1, Info),
+ {'locale', Ds} = lists:keyfind('locale', 1, AttrList),
+ io:format("Locale domains: ~w~n", [Ds]),
+ Match = fun(M, F, A) ->
+ in(M, Ds) andalso in(F, ['string', 'format']) andalso A > 0
+ end,
+
+ function(Match,
+ fun(Form, _Context) ->
+ case erl_syntax:application_arguments(Form) of
+ [H|T] = As ->
+ case erl_eval:exprs([H], []) of
+ {value, Value, _} ->
+ io:format("expanding mes ~ts~n", [Value]),
+ Oper = erl_syntax:application_operator(Form),
+ Hash = l10n_utils:hash(Value),
+ Args = [a(Hash), a(Value)|T],
+ erl_syntax:application(Oper, Args);
+ Other ->
+ erlang:error({cannot_evaluate,
+ [As, Other]})
+ end;
+ _Args ->
+ erlang:error(illegal_form)
+ end
+ end, Forms, Options)
+ catch error:Reason ->
+ io:format("Cancel parse_transform: ~w ~n", [Reason]),
+ Forms
+ end.
+
+revert_tree(Tree) ->
+ [erl_syntax:revert(T) || T <- lists:flatten(Tree)].
+
+a(X) ->
+ erl_syntax:abstract(X).
View
2 src/l10n_sup.erl
@@ -41,7 +41,7 @@
%% ===================================================================
start_link(D) ->
- supervisor:start_link({local, ?MODULE}, ?MODULE, [D]).
+ supervisor:start_link({local, D:get_name('supervisor')}, ?MODULE, [D]).
%% ===================================================================
%% Supervisor callbacks
View
2 src/l10n_utils.erl
@@ -2,7 +2,7 @@
-export([hash/1, format/1, string/1, file_write/2, copy_table/2, get_keys/1]).
hash(X) -> erlang:phash2(X).
-format(X) -> i18n_message:open(X).
+format(X) -> i18n_message:open(string(X)).
string(X) -> i18n_string:from(X).
file_write(FileName, IOList) ->

0 comments on commit c40549e

Please sign in to comment.