2 * This file is part of RawTherapee.
4 * Copyright (c) 2004-2010 Gabor Horvath <hgabor@rawtherapee.com>
6 * RawTherapee is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * RawTherapee is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with RawTherapee. If not, see <http://www.gnu.org/licenses/>.
19 #include <glib/gstdio.h>
20 #include <multilangmgr.h>
25 Glib::ustring
M (std::string key
) { return langMgr
.getStr (key
); }
27 bool MultiLangMgr::load (Glib::ustring fname
, MultiLangMgr
* fb
) {
31 FILE *f
= g_fopen (fname
.c_str(), "rt");
38 char* buffer
= new char[2048];
40 while (buffer
= fgets (buffer
, 2048, f
)) {
43 while (buffer
[seppos
]!=0 && buffer
[seppos
]!=';')
46 if (buffer
[seppos
]==0)
48 // cut the last \n and \r characters
49 int endpos
= strlen(buffer
)-1;
50 while (buffer
[endpos
]=='\n' || buffer
[endpos
]=='\r')
53 // replace "\n" to '\n'
55 for (int i
=0; i
<endpos
+1; i
++)
56 if (i
<endpos
&& buffer
[i
]=='\\' && buffer
[i
+1]=='n') {
61 buffer
[j
++] = buffer
[i
];
65 transTable
[buffer
] = buffer
+ seppos
+ 1;
73 bool MultiLangMgr::save (Glib::ustring fname
) {
75 FILE *f
= g_fopen (fname
.c_str(), "wt");
80 std::map
<std::string
, Glib::ustring
>::iterator r
;
81 for (r
=transTable
.begin (); r
!=transTable
.end(); r
++)
82 fprintf (f
, "%s;%s\n", r
->first
.c_str(), Glib::locale_from_utf8(r
->second
).c_str());
88 Glib::ustring
MultiLangMgr::getStr (std::string key
) {
90 std::map
<std::string
, Glib::ustring
>::iterator r
= transTable
.find (key
);
91 if (r
!=transTable
.end())
94 return fallBack
->getStr (key
);