Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge pull request #8 from bipthelin/master

Added support for app.config
  • Loading branch information...
commit e3893dee0e15009f25479978cefdc7dc807fd7ec 2 parents 2db7a5f + 222cc31
authored December 13, 2011
30  src/gettext_server.erl
@@ -120,10 +120,11 @@ start(CallBackMod, Name) ->
120 120
 %%          ignore               |
121 121
 %%          {stop, Reason}
122 122
 %%--------------------------------------------------------------------
123  
-init([CallBackMod0, Name]) ->
  123
+init([CallBackModConfig, Name]) ->
  124
+	{CallBackMod0, Config} = CallBackModConfig,
124 125
     CallBackMod = get_callback_mod(CallBackMod0),
125  
-    GettextDir = get_gettext_dir(CallBackMod),
126  
-    DefLang = get_default_lang(CallBackMod),
  126
+    GettextDir = get_gettext_dir(CallBackMod, Config),
  127
+    DefLang = get_default_lang(CallBackMod, Config),
127 128
     TableNameStr = atom_to_list(Name) ++ "_db",
128 129
     TableName = list_to_atom(TableNameStr),
129 130
     Cache = create_db(TableName, GettextDir),
@@ -184,7 +185,8 @@ get_default_lang(CallBackMod) ->
184 185
 %%--------------------------------------------------------------------
185 186
 handle_call({key2str, Key, Lang}, _From, State) ->
186 187
     TableName = State#state.table_name,
187  
-    Reply = lookup(TableName, Lang, Key),
  188
+	DefaultLang = State#state.def_lang,
  189
+    Reply = lookup(TableName, Lang, DefaultLang, Key),
188 190
     {reply, Reply, State};
189 191
 %%
190 192
 handle_call({lang2cset, Lang}, _From, State) ->
@@ -272,6 +274,18 @@ code_change(_OldVsn, State, _Extra) ->
272 274
 %%% Internal functions
273 275
 %%--------------------------------------------------------------------
274 276
 
  277
+get_default_lang(CallBackMod, Config) ->
  278
+	case proplists:get_value(default_lang, Config) of
  279
+		undefined -> get_default_lang(CallBackMod);
  280
+		ConfLang -> ConfLang
  281
+	end.
  282
+
  283
+get_gettext_dir(CallBackMod, Config) ->
  284
+	case proplists:get_value(gettext_dir, Config) of
  285
+		undefined -> get_gettext_dir(CallBackMod);
  286
+		ConfDir -> ConfDir
  287
+	end.
  288
+
275 289
 db_filename(TableName, GettextDir) ->
276 290
     filename:join(GettextDir,  atom_to_list(TableName) ++ ".dets").
277 291
 
@@ -487,8 +501,14 @@ insert(TableName, LC, L) ->
487 501
     lists:foreach(F, L).
488 502
 
489 503
 lookup(TableName, Lang, Key) ->
  504
+	lookup(TableName, Lang, Lang, Key).
  505
+
  506
+lookup(TableName, Lang, DefaultLang, Key) ->
490 507
     try ets:lookup(get(ets_table), ?KEY(Lang, Key)) of
491  
-	[]          -> Key;  
  508
+	[] ->  case string:equal(Lang, DefaultLang) of
  509
+				true -> Key;
  510
+				false -> lookup(TableName, DefaultLang, Key)
  511
+			end;
492 512
 	[?ENTRY(_,_,Str)|_] -> Str
493 513
     catch
494 514
         _:_ ->
2  src/gettext_sup.erl
@@ -52,7 +52,7 @@ start_link(Options) ->
52 52
 %%          {error, Reason}   
53 53
 %%----------------------------------------------------------------------
54 54
 init([]) ->
55  
-    init([gettext:callback_mod()]);  % just a default that should always work
  55
+    init([{gettext:callback_mod(),application:get_all_env()}]);  % just a default that should always work
56 56
 init([CallBackMod]) ->
57 57
     GettextServer = {gettext_server,{gettext_server,start_link,[CallBackMod]},
58 58
 	      permanent,5000,worker,[gettext_server]},

0 notes on commit e3893de

Please sign in to comment.
Something went wrong with that request. Please try again.