Browse Source

Fix code style.

Andreas Stenius 11 years ago
parent
commit
c0fedfe3cc
2 changed files with 111 additions and 111 deletions
  1. 84 84
      src/i18n/i18n_manager.erl
  2. 27 27
      src/i18n/po_generator.erl

+ 84 - 84
src/i18n/i18n_manager.erl

@@ -18,111 +18,111 @@
 %%
 
 generate_pos([Lang,Files])->
-        io:format("~s -> ~s ~n",[Lang,Files]),
-        {ok, SplittedLocales} = string:tokens(Lang,","),
-	{ok, SplittedFiles} = string:tokens(Files, ","),
-	ProcessedFiles = sources_parser:parse(SplittedFiles),
-	io:format("Parsed tokens are ~p~n",[ProcessedFiles]),
-	BaseDir = "lang/default/",
-	
-	PopulateTable = fun(Language)->
-						io:format("-------------------------Generating po file for ~s-------------------------~n",[Language]),	
-						open_table(Language),
-						put(locale, Language),
-						insert_tokens(ProcessedFiles),
-						
-						%%Recover already present translations
-						TranslationsForLanguage = po_scanner:parse_po_file(BaseDir ++ Language ++ "/gettext.po"),
-						io:format("Updating translations~n"),
-						insert_translations(TranslationsForLanguage),
-						Data = dets_data(),
-						io:format("Generating po file ~n"),
-						Fuzzy = dets_fuzzy(),
-						po_generator:generate_file(Language, Data, Fuzzy),
-						io:format("Closing files ~n"),
-						close_tables(Language),
-						io:format("All files closed ~n")
-					end,
-	
-	lists:map(PopulateTable, SplittedLocales),
-	init:stop()
-	.
-	  
+    io:format("~s -> ~s ~n",[Lang,Files]),
+    {ok, SplittedLocales} = string:tokens(Lang,","),
+    {ok, SplittedFiles} = string:tokens(Files, ","),
+    ProcessedFiles = sources_parser:parse(SplittedFiles),
+    io:format("Parsed tokens are ~p~n",[ProcessedFiles]),
+    BaseDir = "lang/default/",
+
+    PopulateTable = fun(Language)->
+                            io:format("-------------------------Generating po file for ~s-------------------------~n",[Language]),
+                            open_table(Language),
+                            put(locale, Language),
+                            insert_tokens(ProcessedFiles),
+
+                            %%Recover already present translations
+                            TranslationsForLanguage = po_scanner:parse_po_file(BaseDir ++ Language ++ "/gettext.po"),
+                            io:format("Updating translations~n"),
+                            insert_translations(TranslationsForLanguage),
+                            Data = dets_data(),
+                            io:format("Generating po file ~n"),
+                            Fuzzy = dets_fuzzy(),
+                            po_generator:generate_file(Language, Data, Fuzzy),
+                            io:format("Closing files ~n"),
+                            close_tables(Language),
+                            io:format("All files closed ~n")
+                    end,
+
+    lists:map(PopulateTable, SplittedLocales),
+    init:stop()
+        .
+
 
 %%
 %% Local Functions
 %%
 
 %% Open a temporal table for a given locale
-open_table(Locale)->   
-	Dir = "./lang/tmp/" ++ Locale,
-	io:format("Creating dir ~s~n",[Dir]),
-	file:del_dir(Dir),
-	file:make_dir(Dir),
-	OpenTable = fun({TableName, TableFile}) ->
-		File = Dir ++ TableFile,
-		case dets:open_file(TableName, [{file, File}]) of
-	   		{ok,Ref} ->  io:format("Opened DETS ~p ~p~n",[TableName,Ref]);
-	   		_Error -> io:format("Error opening DETS~p~n",[_Error])
-		end
-	end,
-	
-	lists:map(OpenTable, [{?EPOT_TABLE,"/epot.dets"},{?EPOT_TABLE_FUZZY,"/epot_fuzzy.dets"}]).
-				
+open_table(Locale)->
+    Dir = "./lang/tmp/" ++ Locale,
+    io:format("Creating dir ~s~n",[Dir]),
+    file:del_dir(Dir),
+    file:make_dir(Dir),
+    OpenTable = fun({TableName, TableFile}) ->
+                        File = Dir ++ TableFile,
+                        case dets:open_file(TableName, [{file, File}]) of
+                            {ok,Ref} ->  io:format("Opened DETS ~p ~p~n",[TableName,Ref]);
+                            _Error -> io:format("Error opening DETS~p~n",[_Error])
+                        end
+                end,
+
+    lists:map(OpenTable, [{?EPOT_TABLE,"/epot.dets"},{?EPOT_TABLE_FUZZY,"/epot_fuzzy.dets"}]).
+
 %%TODO better way to do cleanup
 close_tables(Locale) ->
-	%%dets:delete_all_objects(?EPOT_TABLE),
-	ok = dets:close(?EPOT_TABLE),
-	ok = dets:close(?EPOT_TABLE_FUZZY),
-	file:delete("./lang/tmp/" ++ Locale ++ "/epot.dets"),
-	file:delete("./lang/tmp/" ++ Locale ++ "/epot_fuzzy.dets").
+    %%dets:delete_all_objects(?EPOT_TABLE),
+    ok = dets:close(?EPOT_TABLE),
+    ok = dets:close(?EPOT_TABLE_FUZZY),
+    file:delete("./lang/tmp/" ++ Locale ++ "/epot.dets"),
+    file:delete("./lang/tmp/" ++ Locale ++ "/epot_fuzzy.dets").
 
 %%Get all data from dets table
 dets_data() -> dets:foldl(fun(E, Acc) -> [E|Acc] end, [], ?EPOT_TABLE).
 dets_fuzzy() -> dets:foldl(fun(E, Acc) -> [E|Acc] end, [], ?EPOT_TABLE_FUZZY).
 
 insert_tokens([]) -> noop;
-insert_tokens([{Id,{Fname,Line,_Col}}|Tail]) -> 
-	insert_token(Id, Id, Fname, Line),
-	insert_tokens(Tail).
+insert_tokens([{Id,{Fname,Line,_Col}}|Tail]) ->
+    insert_token(Id, Id, Fname, Line),
+    insert_tokens(Tail).
 
 insert_token(Id, Translation,Fname,Line)->
-	FileInfo = get_file_info(Id), %%File info are all files where this string is present
-	AllFileReferences = lists:sort( [{Fname,Line} | FileInfo] ),
-	dets:insert(?EPOT_TABLE, {Id, Translation,AllFileReferences}).
+    FileInfo = get_file_info(Id), %%File info are all files where this string is present
+    AllFileReferences = lists:sort( [{Fname,Line} | FileInfo] ),
+    dets:insert(?EPOT_TABLE, {Id, Translation,AllFileReferences}).
 
 insert_translations([]) -> noop;
-insert_translations(L = [H|T]) -> 
-	%%io:format("Remaining ~p~n",[L]),
-	case H of
-		{comment, _} ->
-			%%Comments are skipped
-			insert_translations(T);
-		_Other ->
-			[{id,Id}, {str,Str}|Tail] = L,
-			insert_translation(Id,Str),
-			insert_translations(Tail)
-  	end.
+insert_translations(L = [H|T]) ->
+    %%io:format("Remaining ~p~n",[L]),
+    case H of
+        {comment, _} ->
+            %%Comments are skipped
+            insert_translations(T);
+        _Other ->
+            [{id,Id}, {str,Str}|Tail] = L,
+            insert_translation(Id,Str),
+            insert_translations(Tail)
+    end.
 
 insert_translation(Id, Translation) ->
-	io:format("Updating translation for ~p to ~p ~n",[Id,Translation]),
-	case Id of 
-		[] ->
-			noop;
-		Id ->
-			case dets:lookup(?EPOT_TABLE,Id) of
-			[] ->
-				%%Fuzzy translation!
-				dets:insert(?EPOT_TABLE_FUZZY, {Id, Translation,fuzzy});	
-			[{Id, _StoredTranslation,FileInfo}] ->
-				%%TODO check for translation unicity
-				io:format("Recovered translation for ~p ~p ~n",[Id,_StoredTranslation]),
-				dets:insert(?EPOT_TABLE, {Id, Translation,FileInfo})
-			end
-	end.
+    io:format("Updating translation for ~p to ~p ~n",[Id,Translation]),
+    case Id of
+        [] ->
+            noop;
+        Id ->
+            case dets:lookup(?EPOT_TABLE,Id) of
+                [] ->
+                    %%Fuzzy translation!
+                    dets:insert(?EPOT_TABLE_FUZZY, {Id, Translation,fuzzy});
+                [{Id, _StoredTranslation,FileInfo}] ->
+                    %%TODO check for translation unicity
+                    io:format("Recovered translation for ~p ~p ~n",[Id,_StoredTranslation]),
+                    dets:insert(?EPOT_TABLE, {Id, Translation,FileInfo})
+            end
+    end.
 
 get_file_info(Key) ->
     case dets:lookup(?EPOT_TABLE, Key) of
-	[]            -> [];
-	[{_,_,Finfo}|_] -> Finfo
+        []            -> [];
+        [{_,_,Finfo}|_] -> Finfo
     end.

+ 27 - 27
src/i18n/po_generator.erl

@@ -16,42 +16,42 @@
 %% API Functions
 %%
 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),
-	
-	gettext_compile:write_header(),
-	io:format("Writing entries~n"),
+    Gettext_App_Name = "tmp",
+    GtxtDir = ".",
+    io:format("Opening po file"),
+    gettext_compile:open_po_file(Gettext_App_Name, GtxtDir, Lang),
+
+    gettext_compile:write_header(),
+    io:format("Writing entries~n"),
     write_entries(Items),
-	io:format("Writing fuzzy entries~n"),
-	write_fuzzy_entries(Fuzzy), 
+    io:format("Writing fuzzy entries~n"),
+    write_fuzzy_entries(Fuzzy),
     gettext_compile:close_file().
 
 %%
 %% Local Functions
 %%
 write_entries(Items)->
-	Fd = get(fd),
+    Fd = get(fd),
     F = fun({Id,Translation,Finfo}) ->
-		Fi = gettext_compile:fmt_fileinfo(Finfo),
-		io:format(Fd, "~n#: ~s~n", [Fi]),
-		file:write(Fd, "msgid \"\"\n"),
-		gettext_compile:write_pretty(Id),
-		file:write(Fd, "msgstr \"\"\n"),
-		gettext_compile:write_pretty(Translation)
-	end,
+                Fi = gettext_compile:fmt_fileinfo(Finfo),
+                io:format(Fd, "~n#: ~s~n", [Fi]),
+                file:write(Fd, "msgid \"\"\n"),
+                gettext_compile:write_pretty(Id),
+                file:write(Fd, "msgstr \"\"\n"),
+                gettext_compile:write_pretty(Translation)
+        end,
     lists:foreach(F, Items).
 
 write_fuzzy_entries(Items) ->
-	Fd = get(fd),
-	file:write(Fd, "\n"),
-	F = fun({Id,Translation,_}) ->
-		file:write(Fd, "#, fuzzy\n"),
-		file:write(Fd, "msgid \"\"\n"),
-		gettext_compile:write_pretty(Id),
-		file:write(Fd, "msgstr \"\"\n"),
-		gettext_compile:write_pretty(Translation),
-		file:write(Fd, "\n")
-	end,
+    Fd = get(fd),
+    file:write(Fd, "\n"),
+    F = fun({Id,Translation,_}) ->
+                file:write(Fd, "#, fuzzy\n"),
+                file:write(Fd, "msgid \"\"\n"),
+                gettext_compile:write_pretty(Id),
+                file:write(Fd, "msgstr \"\"\n"),
+                gettext_compile:write_pretty(Translation),
+                file:write(Fd, "\n")
+        end,
     lists:foreach(F, Items).