1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
14 #include <rtl/string.hxx>
15 #include <rtl/ustring.hxx>
16 #include <osl/file.hxx>
19 // Translated style names must be unique
20 static void checkStyleNames(const OString
& aLanguage
)
22 std::map
<OString
,sal_uInt16
> aLocalizedStyleNames
;
23 std::map
<OString
,sal_uInt16
> aLocalizedNumStyleNames
;
24 std::list
<PoEntry
> repeatedEntries
;
26 OString aPoPath
= OString(getenv("SRC_ROOT")) +
27 "/translations/source/" +
28 aLanguage
+ "/sw/source/ui/utlui.po";
30 aPoInput
.open(aPoPath
);
31 if( !aPoInput
.isOpen() )
32 std::cerr
<< "Warning: Cannot open " << aPoPath
<< std::endl
;
37 aPoInput
.readEntry(aPoEntry
);
38 bool bRepeated
= false;
44 if( !aPoEntry
.isFuzzy() && aPoEntry
.getSourceFile() == "poolfmt.src" &&
45 aPoEntry
.getGroupId().startsWith("STR_POOLCOLL") )
47 OString aMsgStr
= aPoEntry
.getMsgStr();
48 if( aMsgStr
.isEmpty() )
50 if( aLocalizedStyleNames
.find(aMsgStr
) == aLocalizedStyleNames
.end() )
51 aLocalizedStyleNames
[aMsgStr
] = 1;
53 aLocalizedStyleNames
[aMsgStr
]++;
57 if( !aPoEntry
.isFuzzy() && aPoEntry
.getSourceFile() == "poolfmt.src" &&
58 aPoEntry
.getGroupId().startsWith("STR_POOLNUMRULE") )
60 OString aMsgStr
= aPoEntry
.getMsgStr();
61 if( aMsgStr
.isEmpty() )
63 if( aLocalizedNumStyleNames
.find(aMsgStr
) == aLocalizedNumStyleNames
.end() )
64 aLocalizedNumStyleNames
[aMsgStr
] = 1;
66 aLocalizedNumStyleNames
[aMsgStr
]++;
71 repeatedEntries
.push_back(aPoEntry
);
75 for( std::map
<OString
,sal_uInt16
>::iterator it
=aLocalizedStyleNames
.begin(); it
!=aLocalizedStyleNames
.end(); ++it
)
79 std::cout
<< "ERROR: Style name translations must be unique in:\n" <<
80 aPoPath
<< "\nLanguage: " << aLanguage
<< "\nDuplicated translation is: " << it
->first
<<
81 "\nSee STR_POOLCOLL_*\n\n";
84 for( std::map
<OString
,sal_uInt16
>::iterator it
=aLocalizedNumStyleNames
.begin(); it
!=aLocalizedNumStyleNames
.end(); ++it
)
88 std::cout
<< "ERROR: Style name translations must be unique in:\n" <<
89 aPoPath
<< "\nLanguage: " << aLanguage
<< "\nDuplicated translation is: " << it
->first
<<
90 "\nSee STR_POOLNUMRULE_*\n\n";
93 aPoInput
.open(aPoPath
);
94 if( !aPoInput
.isOpen() )
95 std::cerr
<< "Warning: Cannot open " << aPoPath
<< std::endl
;
97 aPoOutput
.open(aPoPath
+".new");
98 PoHeader
aTmp("sw/source/ui/utlui");
99 aPoOutput
.writeHeader(aTmp
);
100 bool bAnyError
= false;
106 aPoInput
.readEntry(aPoEntry
);
109 for ( std::list
<PoEntry
>::iterator it
=repeatedEntries
.begin(); it
!=repeatedEntries
.end(); ++it
) {
110 if (it
->getMsgId() == aPoEntry
.getMsgId() && it
->getGroupId() == aPoEntry
.getGroupId()) {
118 aPoOutput
.writeEntry(aPoEntry
);
124 osl::FileBase::getFileURLFromSystemPath(OStringToOUString(aPoPath
, RTL_TEXTENCODING_UTF8
), aPoPathURL
);
126 osl::File::move(aPoPathURL
+ ".new", aPoPathURL
);
128 osl::File::remove(aPoPathURL
+ ".new");
132 // Translated spreadsheet function names must be unique
133 static void checkFunctionNames(const OString
& aLanguage
)
135 std::map
<OString
,sal_uInt16
> aLocalizedFunctionNames
;
136 std::map
<OString
,sal_uInt16
> aLocalizedCoreFunctionNames
;
138 std::list
<PoEntry
> repeatedEntries
;
143 aPoPaths
[0] = OString(getenv("SRC_ROOT")) +
144 "/translations/source/" +
146 "/formula/source/core/resource.po";
148 aPoInput
.open(aPoPaths
[0]);
149 if( !aPoInput
.isOpen() )
150 std::cerr
<< "Warning: Cannot open " << aPoPaths
[0] << std::endl
;
155 aPoInput
.readEntry(aPoEntry
);
158 if( !aPoEntry
.isFuzzy() && aPoEntry
.getGroupId() == "RID_STRLIST_FUNCTION_NAMES" )
160 OString aMsgStr
= aPoEntry
.getMsgStr();
161 if( aMsgStr
.isEmpty() )
163 if( aLocalizedCoreFunctionNames
.find(aMsgStr
) == aLocalizedCoreFunctionNames
.end() )
164 aLocalizedCoreFunctionNames
[aMsgStr
] = 1;
165 if( aLocalizedFunctionNames
.find(aMsgStr
) == aLocalizedFunctionNames
.end() ) {
166 aLocalizedFunctionNames
[aMsgStr
] = 1;
168 aLocalizedFunctionNames
[aMsgStr
]++;
169 repeatedEntries
.push_back(aPoEntry
);
175 aPoPaths
[1] = OString(getenv("SRC_ROOT")) +
176 "/translations/source/" +
178 "/scaddins/source/analysis.po";
179 aPoInput
.open(aPoPaths
[1]);
180 if( !aPoInput
.isOpen() )
181 std::cerr
<< "Warning: Cannot open " << aPoPaths
[1] << std::endl
;
186 aPoInput
.readEntry(aPoEntry
);
189 if( !aPoEntry
.isFuzzy() && aPoEntry
.getGroupId() == "RID_ANALYSIS_FUNCTION_NAMES" )
191 OString aMsgStr
= aPoEntry
.getMsgStr();
192 if( aMsgStr
.isEmpty() )
194 if( aLocalizedCoreFunctionNames
.find(aMsgStr
) != aLocalizedCoreFunctionNames
.end() )
196 if( aLocalizedFunctionNames
.find(aMsgStr
) == aLocalizedFunctionNames
.end() ) {
197 aLocalizedFunctionNames
[aMsgStr
] = 1;
199 aLocalizedFunctionNames
[aMsgStr
]++;
200 repeatedEntries
.push_back(aPoEntry
);
207 aPoPaths
[2] = OString(getenv("SRC_ROOT")) +
208 "/translations/source/" +
210 "/scaddins/source/datefunc.po";
211 aPoInput
.open(aPoPaths
[2]);
212 if( !aPoInput
.isOpen() )
213 std::cerr
<< "Warning: Cannot open " << aPoPaths
[2] << std::endl
;
218 aPoInput
.readEntry(aPoEntry
);
221 if( !aPoEntry
.isFuzzy() && aPoEntry
.getGroupId() == "RID_DATE_FUNCTION_NAMES" )
223 OString aMsgStr
= aPoEntry
.getMsgStr();
224 if( aMsgStr
.isEmpty() )
226 if( aLocalizedCoreFunctionNames
.find(aMsgStr
) != aLocalizedCoreFunctionNames
.end() )
228 if( aLocalizedFunctionNames
.find(aMsgStr
) == aLocalizedFunctionNames
.end() ) {
229 aLocalizedFunctionNames
[aMsgStr
] = 1;
231 aLocalizedFunctionNames
[aMsgStr
]++;
232 repeatedEntries
.push_back(aPoEntry
);
238 aPoPaths
[3] = OString(getenv("SRC_ROOT")) +
239 "/translations/source/" +
241 "/scaddins/source/pricing.po";
242 aPoInput
.open(aPoPaths
[3]);
243 if( !aPoInput
.isOpen() )
244 std::cerr
<< "Warning: Cannot open " << aPoPaths
[3] << std::endl
;
249 aPoInput
.readEntry(aPoEntry
);
255 if( !aPoEntry
.isFuzzy() && aPoEntry
.getGroupId() == "RID_PRICING_FUNCTION_NAMES" )
257 OString aMsgStr
= aPoEntry
.getMsgStr();
258 if( aMsgStr
.isEmpty() )
260 if( aLocalizedCoreFunctionNames
.find(aMsgStr
) != aLocalizedCoreFunctionNames
.end() )
262 if( aLocalizedFunctionNames
.find(aMsgStr
) == aLocalizedFunctionNames
.end() ) {
263 aLocalizedFunctionNames
[aMsgStr
] = 1;
265 aLocalizedFunctionNames
[aMsgStr
]++;
266 repeatedEntries
.push_back(aPoEntry
);
271 for( std::map
<OString
,sal_uInt16
>::iterator it
=aLocalizedFunctionNames
.begin(); it
!=aLocalizedFunctionNames
.end(); ++it
)
276 << ("ERROR: Spreadsheet function name translations must be"
277 " unique.\nLanguage: ")
278 << aLanguage
<< "\nDuplicated translation is: " << it
->first
283 for (int i
=0;i
<4;i
++)
285 aPoInput
.open(aPoPaths
[i
]);
286 if( !aPoInput
.isOpen() )
287 std::cerr
<< "Warning: Cannot open " << aPoPaths
[i
] << std::endl
;
288 PoOfstream aPoOutput
;
289 aPoOutput
.open(aPoPaths
[i
]+".new");
295 PoHeader
hd(OString("formula/source/core/resource"));
296 aPoOutput
.writeHeader(hd
);
301 PoHeader
hd(OString("scaddins/source/analysis"));
302 aPoOutput
.writeHeader(hd
);
307 PoHeader
hd(OString("scaddins/source/datefunc"));
308 aPoOutput
.writeHeader(hd
);
313 PoHeader
hd(OString("scaddins/source/pricing"));
314 aPoOutput
.writeHeader(hd
);
318 bool bAnyError
= false;
324 aPoInput
.readEntry(aPoEntry
);
327 for ( std::list
<PoEntry
>::iterator it
=repeatedEntries
.begin(); it
!=repeatedEntries
.end(); ++it
)
329 if (it
->getMsgId() == aPoEntry
.getMsgId() && it
->getGroupId() == aPoEntry
.getGroupId())
341 aPoOutput
.writeEntry(aPoEntry
);
346 osl::FileBase::getFileURLFromSystemPath(OStringToOUString(aPoPaths
[i
], RTL_TEXTENCODING_UTF8
), aPoPathURL
);
348 osl::File::move(aPoPathURL
+ ".new", aPoPathURL
);
350 osl::File::remove(aPoPathURL
+ ".new");
354 // In instsetoo_native/inc_openoffice/windows/msi_languages.po
355 // where an en-US string ends with '|', translation must end
357 static void checkVerticalBar(const OString
& aLanguage
)
359 OString aPoPath
= OString(getenv("SRC_ROOT")) +
360 "/translations/source/" +
362 "/instsetoo_native/inc_openoffice/windows/msi_languages.po";
364 aPoInput
.open(aPoPath
);
365 PoOfstream aPoOutput
;
366 aPoOutput
.open(aPoPath
+".new");
367 if( !aPoInput
.isOpen() )
368 std::cerr
<< "Warning: Cannot open " << aPoPath
<< std::endl
;
369 PoHeader
aTmp("instsetoo_native/inc_openoffice/windows/msi_languages");
370 aPoOutput
.writeHeader(aTmp
);
376 aPoInput
.readEntry(aPoEntry
);
379 if( !aPoEntry
.isFuzzy() && aPoEntry
.getMsgId().endsWith("|") &&
380 !aPoEntry
.getMsgStr().isEmpty() && !aPoEntry
.getMsgStr().endsWith("|") )
383 << ("ERROR: Missing '|' character at the end of translated"
384 " string.\nIt causes runtime error in installer.\nFile: ")
385 << aPoPath
<< std::endl
386 << "Language: " << aLanguage
<< std::endl
387 << "English: " << aPoEntry
.getMsgId() << std::endl
388 << "Localized: " << aPoEntry
.getMsgStr() << std::endl
393 aPoOutput
.writeEntry(aPoEntry
);
398 osl::FileBase::getFileURLFromSystemPath(OStringToOUString(aPoPath
, RTL_TEXTENCODING_UTF8
), aPoPathURL
);
400 osl::File::move(aPoPathURL
+ ".new", aPoPathURL
);
402 osl::File::remove(aPoPathURL
+ ".new");
405 // In starmath/source.po Math symbol names (from symbol.src)
406 // must not contain spaces
407 static void checkMathSymbolNames(const OString
& aLanguage
)
409 OString aPoPath
= OString(getenv("SRC_ROOT")) +
410 "/translations/source/" +
412 "/starmath/source.po";
414 aPoInput
.open(aPoPath
);
415 PoOfstream aPoOutput
;
416 aPoOutput
.open(aPoPath
+".new");
417 if( !aPoInput
.isOpen() )
418 std::cerr
<< "Warning: Cannot open " << aPoPath
<< std::endl
;
419 PoHeader
aTmp("starmath/source");
420 aPoOutput
.writeHeader(aTmp
);
426 aPoInput
.readEntry(aPoEntry
);
429 if( !aPoEntry
.isFuzzy() && aPoEntry
.getGroupId() == "RID_UI_SYMBOL_NAMES" &&
430 !aPoEntry
.getMsgStr().isEmpty() && (aPoEntry
.getMsgStr().indexOf(" ") != -1) )
433 << "ERROR: Math symbol names must not contain spaces.\nFile: "
434 << aPoPath
<< std::endl
435 << "Language: " << aLanguage
<< std::endl
436 << "English: " << aPoEntry
.getMsgId() << std::endl
437 << "Localized: " << aPoEntry
.getMsgStr() << std::endl
442 aPoOutput
.writeEntry(aPoEntry
);
447 osl::FileBase::getFileURLFromSystemPath(OStringToOUString(aPoPath
, RTL_TEXTENCODING_UTF8
), aPoPathURL
);
449 osl::File::move(aPoPathURL
+ ".new", aPoPathURL
);
451 osl::File::remove(aPoPathURL
+ ".new");
456 OString
aLanguages(getenv("ALL_LANGS"));
457 if( aLanguages
.isEmpty() )
459 std::cerr
<< "Usage: bin/run pocheck\n";
462 for(sal_Int32 i
= 1;;++i
) // skip en-US
464 OString aLanguage
= aLanguages
.getToken(i
,' ');
465 if( aLanguage
.isEmpty() )
467 if( aLanguage
== "qtz" )
469 checkStyleNames(aLanguage
);
470 checkFunctionNames(aLanguage
);
471 checkVerticalBar(aLanguage
);
472 checkMathSymbolNames(aLanguage
);
477 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */