Use relative paths instead of full path to avoid too long commands
[scilab.git] / scilab / tools / localization / generatePoFile.sce
1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2 // Copyright (C) 2007 - INRIA - Allan CORNET
3 // Copyright (C) 2011-2012 - DIGITEO - Allan CORNET
4 //
5 // This file must be used under the terms of the CeCILL.
6 // This source file is licensed as described in the file COPYING, which
7 // you should have received as part of this distribution.  The terms
8 // are also available at
9 // http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
10
11 function  generatePoFile(LANGUAGE)
12     if getos() <> "Windows" then
13         error(999, "Used only under Windows");
14     end
15
16     if ~isdef("%c_a_c") then
17         exec("SCI/modules/overloading/macros/%c_a_c.sci");
18     end
19
20     LC = "LC_MESSAGES";
21     DEST_PATH_MO = SCI + filesep() + "locale" + filesep() + LANGUAGE + filesep() + LC + filesep();
22     DEST_FILE_MO = "scilab.mo";
23     DEST_FILE_PO = "scilab.po";
24     LC = "LC_MESSAGES";
25     PATH_GETTEXT_TOOLS = SCI + filesep() + "tools/gettext";
26     PATH_GETTEXT_TOOLS = getrelativefilename(DEST_PATH_MO, PATH_GETTEXT_TOOLS);
27
28     // make destination directories
29     if ~isdir(SCI + filesep() + "locale") then
30         createdir(SCI + filesep() + "locale");
31     end
32
33     if ~isdir(SCI + filesep() + "locale" + filesep() + LANGUAGE) then
34         createdir(SCI + filesep() + "locale" + filesep() + LANGUAGE);
35     end
36
37     if ~isdir(SCI + filesep() + "locale" + filesep() + LANGUAGE + filesep() + LC) then
38         createdir(SCI + filesep() + "locale" + filesep() + LANGUAGE + filesep() + LC);
39     end
40
41     Modules = getmodules();
42     PATH_PO = SCI + filesep() + "modules" + filesep() + Modules + filesep() + "locales" + filesep();
43     if LANGUAGE ==  "en_US" then
44         FILENAME_PO = Modules + ".pot";
45     else
46         FILENAME_PO = LANGUAGE + ".po";
47     end
48
49     List_files = [];
50     for k = 1:size(PATH_PO, "*")
51         if LANGUAGE ==  "en_US" then
52             if findfiles(PATH_PO(k), FILENAME_PO(k)) <> [] then
53                 List_files = [List_files ; getrelativefilename(DEST_PATH_MO, fullpath(PATH_PO(k) +  FILENAME_PO(k)))];
54             end
55         else
56             if findfiles(PATH_PO(k), FILENAME_PO) <> [] then
57                 List_files = [List_files ; getrelativefilename(DEST_PATH_MO, fullpath(PATH_PO(k) +  FILENAME_PO))];
58             end
59         end
60     end
61
62     if (List_files <> []) then
63         if newest([DEST_PATH_MO + DEST_FILE_MO; DEST_PATH_MO + List_files]) <> 1 then
64             curPath = pwd();
65             cd(DEST_PATH_MO)
66             cmdline_msgcat = PATH_GETTEXT_TOOLS + filesep() + "msgcat --use-first -o " + DEST_FILE_PO + " " + strcat("""" + List_files + """", " ");
67             unix(cmdline_msgcat);
68             cmline_msgfmt = PATH_GETTEXT_TOOLS + filesep() + "msgfmt --statistics -o " + DEST_FILE_MO + " " + DEST_FILE_PO;
69             unix(cmline_msgfmt);
70             cd(curPath)
71         end
72     end
73
74 endfunction
75 // ======================================
76 function languages = findLanguagesToBuild()
77     languages = [];
78
79     f1 = findfiles("SCI/modules/core/locales/", "*.pot");
80     f2 = findfiles("SCI/modules/core/locales/", "*.po");
81
82     if f1 <> [] then
83         languages = ["en_US"];
84     end
85
86     if f2 <> [] then
87         f2 = strsubst(f2, ".po", "");
88         languages = [languages, f2'];
89     end
90 endfunction
91 // ======================================
92 // Main
93 LANGUAGES = findLanguagesToBuild();
94 mprintf("-- Build localization (.mo from .po) --\n");
95
96 for L = LANGUAGES
97     mprintf("    -- Building for ""%s"" --\n", L);
98     generatePoFile(L);
99 end
100 // ======================================