summaryrefslogtreecommitdiff
path: root/l10ntools
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2012-08-07 12:08:08 +0100
committerCaolán McNamara <caolanm@redhat.com>2012-09-28 08:48:33 +0100
commite967b156cdd2329a1ea106b6ea9517318f5ed81e (patch)
treed73be6f99a963626419e843e2c5178dadc8346f7 /l10ntools
parentbfd20bfb3a0344cca10034674a822530ccb950f9 (diff)
merge .ui translations back to runtime files
Change-Id: Ia01ef21441220293343370df7d865c7eb889bc84
Diffstat (limited to 'l10ntools')
-rw-r--r--l10ntools/inc/export.hxx6
-rw-r--r--l10ntools/source/merge.cxx2
-rw-r--r--l10ntools/source/uimerge.cxx120
3 files changed, 97 insertions, 31 deletions
diff --git a/l10ntools/inc/export.hxx b/l10ntools/inc/export.hxx
index 8e4be09799de..d11d06f0e4e1 100644
--- a/l10ntools/inc/export.hxx
+++ b/l10ntools/inc/export.hxx
@@ -421,8 +421,7 @@ class MergeDataFile;
class MergeData
{
-friend class MergeDataFile;
-private:
+public:
rtl::OString sTyp;
rtl::OString sGID;
rtl::OString sLID;
@@ -468,7 +467,8 @@ class MergeDataFile
~MergeDataFile();
- std::vector<rtl::OString> GetLanguages();
+ std::vector<rtl::OString> GetLanguages() const;
+ const MergeDataHashMap& getMap() const { return aMap; }
PFormEntrys *GetPFormEntrys( ResData *pResData );
PFormEntrys *GetPFormEntrysCaseSensitive( ResData *pResData );
diff --git a/l10ntools/source/merge.cxx b/l10ntools/source/merge.cxx
index fd53f1ceddba..961edec2df5d 100644
--- a/l10ntools/source/merge.cxx
+++ b/l10ntools/source/merge.cxx
@@ -190,7 +190,7 @@ MergeDataFile::~MergeDataFile()
delete aI->second;
}
-std::vector<rtl::OString> MergeDataFile::GetLanguages()
+std::vector<rtl::OString> MergeDataFile::GetLanguages() const
{
return std::vector<rtl::OString>(aLanguageSet.begin(),aLanguageSet.end());
}
diff --git a/l10ntools/source/uimerge.cxx b/l10ntools/source/uimerge.cxx
index d84eaa654801..cd7443e72725 100644
--- a/l10ntools/source/uimerge.cxx
+++ b/l10ntools/source/uimerge.cxx
@@ -118,33 +118,8 @@ void GetOutputFile( int argc, char* argv[])
}
}
-SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv)
+int extractTranslations()
{
- int nRetValue = 0;
- xsltStylesheetPtr stylesheet = 0;
-
- GetOutputFile( argc, argv );
-
- if (sOutputFile.isEmpty())
- {
- fprintf( stdout, "Syntax: UIEX[-p Prj][-r PrjRoot]-i FileIn [-o FileOut][-m DataBase][-e][-L l1,l2,...]\n" );
- fprintf( stdout, " Prj: Project\n" );
- fprintf( stdout, " PrjRoot: Path to project root (..\\.. etc.)\n" );
- fprintf( stdout, " FileIn: Source files (*.src)\n" );
- fprintf( stdout, " FileOut: Destination file (*.*)\n" );
- fprintf( stdout, " DataBase: Mergedata (*.sdf)\n" );
- fprintf( stdout, " -e: Disable writing errorlog\n" );
- fprintf( stdout, " -b: Break when Token \"HelpText\" found in source\n" );
- fprintf( stdout, " -L: Restrict the handled languages. l1,l2,... are elements of (de,en-US,es...)\n" );
- return 1;
- }
-
- if (Export::sLanguages != "en-US")
- {
- fprintf(stderr, "can only extract en-US\n");
- return 1;
- }
-
FILE *pOutFile = fopen(sOutputFile.getStr(), "w");
if (!pOutFile)
{
@@ -156,7 +131,7 @@ SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv)
rtl::OString sStyleSheet = rtl::OString(getenv("SRC_ROOT")) + rtl::OString("/solenv/bin/uilangfilter.xslt");
- stylesheet = xsltParseStylesheetFile ((const xmlChar *)sStyleSheet.getStr());
+ xsltStylesheetPtr stylesheet = xsltParseStylesheetFile ((const xmlChar *)sStyleSheet.getStr());
xmlDocPtr doc = xmlParseFile(sInputFileName.getStr());
@@ -188,6 +163,97 @@ SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv)
fclose(pOutFile);
+ return 0;
+}
+
+
+bool Merge(
+ const rtl::OString &rSDFFile,
+ const rtl::OString &rSourceFile,
+ const rtl::OString &rDestinationFile)
+{
+ Export::InitLanguages( true );
+ 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";
+
+ MergeDataFile aMergeDataFile( rSDFFile, rSourceFile, sal_False );
+ rtl::OString sTmp( Export::sLanguages );
+ if( sTmp.equalsIgnoreAsciiCaseL(RTL_CONSTASCII_STRINGPARAM("ALL")) )
+ Export::SetLanguages( aMergeDataFile.GetLanguages() );
+
+ std::vector<rtl::OString> aLanguages = Export::GetLanguages();
+
+ const MergeDataHashMap& rMap = aMergeDataFile.getMap();
+
+ for(size_t n = 0; n < aLanguages.size(); ++n)
+ {
+ rtl::OString sCur = aLanguages[ n ];
+ if (sCur.isEmpty() || sCur.equalsIgnoreAsciiCaseL(RTL_CONSTASCII_STRINGPARAM("en-US")))
+ continue;
+ 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, sCur);
+
+ if (sOut.isEmpty())
+ continue;
+
+ aDestination << " <e "
+ << "g=\"" << aI->second->sGID.getStr() << "\" "
+ << "i=\"" << aI->second->sLID.getStr() << "\">"
+ << sOut.getStr() << "</e>\n";
+ }
+ }
+
+ aDestination << "</t>";
+ aDestination.close();
+ return sal_True;
+}
+
+SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv)
+{
+ int nRetValue = 0;
+
+ GetOutputFile( argc, argv );
+
+ if (sOutputFile.isEmpty())
+ {
+ fprintf( stdout, "Syntax: UIEX[-p Prj][-r PrjRoot]-i FileIn [-o FileOut][-m DataBase][-e][-L l1,l2,...]\n" );
+ fprintf( stdout, " Prj: Project\n" );
+ fprintf( stdout, " PrjRoot: Path to project root (..\\.. etc.)\n" );
+ fprintf( stdout, " FileIn: Source files (*.src)\n" );
+ fprintf( stdout, " FileOut: Destination file (*.*)\n" );
+ fprintf( stdout, " DataBase: Mergedata (*.sdf)\n" );
+ fprintf( stdout, " -e: Disable writing errorlog\n" );
+ fprintf( stdout, " -L: Restrict the handled languages. l1,l2,... are elements of (de,en-US,es...)\n" );
+ return 1;
+ }
+
+ if (!bMergeMode)
+ {
+ if (Export::sLanguages != "en-US")
+ {
+ fprintf(stderr, "only en-US can exist in source .ui files\n");
+ nRetValue = 1;
+ }
+ else
+ nRetValue = extractTranslations();
+ }
+ else
+ {
+ Merge(sMergeSrc, sInputFileName, sOutputFile);
+ }
+
return nRetValue;
}