Kaydet (Commit) c27b2e37 authored tarafından David Tardon's avatar David Tardon

let uiex produce more translations in one run

uiex differs from the other *ex tools in that translation for every
language must be in a standalone file, named after the language code. So
uiex should take an output _directory_ instead of a file.

Change-Id: If3ed966147c6d11d1fe85c484463f1bca4eec172
üst 58aca95a
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
#include <sal/main.h> #include <sal/main.h>
#include <osl/file.hxx>
#include <rtl/strbuf.hxx> #include <rtl/strbuf.hxx>
#include <libexslt/exslt.h> #include <libexslt/exslt.h>
...@@ -125,22 +127,76 @@ namespace ...@@ -125,22 +127,76 @@ namespace
} }
return sReturn.makeStringAndClear(); return sReturn.makeStringAndClear();
} }
bool lcl_MergeLang(
const MergeDataHashMap &rMap,
const rtl::OString &rLanguage,
const rtl::OString &rDestinationFile)
{
std::ofstream aDestination(
rDestinationFile.getStr(), std::ios_base::out | std::ios_base::trunc);
if (!aDestination.is_open()) {
return false;
}
aDestination << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
aDestination << "<t>\n";
for (MergeDataHashMap::const_iterator aI = rMap.begin(), aEnd = rMap.end(); aI != aEnd; ++aI)
{
if (aI->second->sGID.isEmpty())
continue;
PFormEntrys* pFoo = aI->second->GetPFormEntries();
rtl::OString sOut;
pFoo->GetText( sOut, STRING_TYP_TEXT, rLanguage );
if (sOut.isEmpty())
continue;
aDestination << " <e "
<< "g=\"" << aI->second->sGID.getStr() << "\" "
<< "i=\"" << aI->second->sLID.getStr() << "\">"
<< QuotHTML(sOut).getStr() << "</e>\n";
}
aDestination << "</t>";
aDestination.close();
return true;
}
} }
bool Merge( bool Merge(
const rtl::OString &rSDFFile, const rtl::OString &rSDFFile,
const rtl::OString &rSourceFile, const rtl::OString &rSourceFile,
const rtl::OString &rDestinationFile) const rtl::OString &rDestinationDir)
{ {
Export::InitLanguages( true ); {
std::ofstream aDestination( bool bDestinationIsDir(false);
rDestinationFile.getStr(), std::ios_base::out | std::ios_base::trunc);
if (!aDestination.is_open()) { const rtl::OUString aDestDir(rtl::OStringToOUString(rDestinationDir, RTL_TEXTENCODING_UTF8));
return false; rtl::OUString aDestDirUrl;
if (osl::FileBase::E_None == osl::FileBase::getFileURLFromSystemPath(aDestDir, aDestDirUrl))
{
osl::DirectoryItem aTmp;
if (osl::DirectoryItem::E_None == osl::DirectoryItem::get(aDestDirUrl, aTmp))
{
osl::FileStatus aDestinationStatus(osl_FileStatus_Mask_Type);
if (osl::DirectoryItem::E_None == aTmp.getFileStatus(aDestinationStatus))
bDestinationIsDir = aDestinationStatus.isDirectory();
}
}
if (!bDestinationIsDir)
{
fprintf(stderr, "%s must be a directory\n", rDestinationDir.getStr());
return false;
}
} }
aDestination << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; Export::InitLanguages( true );
aDestination << "<t>\n";
MergeDataFile aMergeDataFile( rSDFFile, rSourceFile, sal_False ); MergeDataFile aMergeDataFile( rSDFFile, rSourceFile, sal_False );
rtl::OString sTmp( Export::sLanguages ); rtl::OString sTmp( Export::sLanguages );
...@@ -150,34 +206,20 @@ bool Merge( ...@@ -150,34 +206,20 @@ bool Merge(
std::vector<rtl::OString> aLanguages = Export::GetLanguages(); std::vector<rtl::OString> aLanguages = Export::GetLanguages();
const MergeDataHashMap& rMap = aMergeDataFile.getMap(); const MergeDataHashMap& rMap = aMergeDataFile.getMap();
const rtl::OString aDestinationDir(rDestinationDir + "/");
bool bResult = true;
for(size_t n = 0; n < aLanguages.size(); ++n) for(size_t n = 0; n < aLanguages.size(); ++n)
{ {
rtl::OString sCur = aLanguages[ n ]; rtl::OString sCur = aLanguages[ n ];
if (sCur.isEmpty() || sCur.equalsIgnoreAsciiCaseL(RTL_CONSTASCII_STRINGPARAM("en-US"))) if (sCur.isEmpty() || sCur.equalsIgnoreAsciiCaseL(RTL_CONSTASCII_STRINGPARAM("en-US")))
continue; continue;
for (MergeDataHashMap::const_iterator aI = rMap.begin(), aEnd = rMap.end(); aI != aEnd; ++aI) const rtl::OString aDestinationFile(aDestinationDir + sCur + ".ui");
{ if (!lcl_MergeLang(rMap, sCur, aDestinationFile))
if (aI->second->sGID.isEmpty()) bResult = false;
continue;
PFormEntrys* pFoo = aI->second->GetPFormEntries();
rtl::OString sOut;
pFoo->GetText( sOut, STRING_TYP_TEXT, sCur);
if (sOut.isEmpty())
continue;
aDestination << " <e "
<< "g=\"" << aI->second->sGID.getStr() << "\" "
<< "i=\"" << aI->second->sLID.getStr() << "\">"
<< QuotHTML(sOut).getStr() << "</e>\n";
}
} }
aDestination << "</t>"; return bResult;
aDestination.close();
return sal_True;
} }
SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv) SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv)
......
...@@ -22,7 +22,7 @@ echo $(POFILES) > $${MERGEINPUT} && \ ...@@ -22,7 +22,7 @@ echo $(POFILES) > $${MERGEINPUT} && \
$(call gb_Helper_abbreviate_dirs,\ $(call gb_Helper_abbreviate_dirs,\
$(gb_UILocalizeTarget_COMMAND) \ $(gb_UILocalizeTarget_COMMAND) \
-i $(UI_FILE) \ -i $(UI_FILE) \
-o $(1) \ -o $(dir $(1)) \
-l $(UI_LANG) \ -l $(UI_LANG) \
-m $${MERGEINPUT} ) && \ -m $${MERGEINPUT} ) && \
rm -rf $${MERGEINPUT} rm -rf $${MERGEINPUT}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment