Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 3924f83358
Fetching contributors…

Cannot retrieve contributors at this time

54 lines (40 sloc) 1.252 kb
%% @doc Chicago Boss translator service
-module(boss_translator).
-export([start/0, start/1, stop/0]).
-export([
is_loaded/2,
lookup/3,
fun_for/2,
reload/2,
reload_all/1
]).
-export([trans/3]).
start() ->
start([]).
start(Options) ->
boss_translator_sup:start_link(Options).
stop() ->
ok.
%% @spec lookup(Key::string(), Locale::string()) -> Translation::string() | undefined
lookup(Pid, Key, Locale) ->
gen_server:call(Pid, {lookup, Key, Locale}).
%% @spec is_loaded(Locale::string()) -> true | false
is_loaded(Pid, Locale) ->
gen_server:call(Pid, {is_loaded, Locale}).
%% @spec reload(Locale::string()) -> ok | {error, Reason}
reload(Pid, Locale) ->
gen_server:call(Pid, {reload, Locale}).
%% @spec reload_all() -> ok | {error, Reason}
reload_all(Pid) ->
gen_server:call(Pid, reload_all).
%% @spec fun_for(Locale::string()) -> TranslationFun::function() | none
fun_for(Pid, Locale) ->
case is_loaded(Pid, Locale) of
true -> fun(String) -> ?MODULE:lookup(Pid, String, Locale) end;
false -> none
end.
trans(App,T,Lang) ->
case boss_translator:lookup(boss_web:translator_pid(App), T, Lang) of
undefined -> T;
S-> S
end.
Jump to Line
Something went wrong with that request. Please try again.