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/.
12 #include <osl/file.hxx>
14 #include <rtl/strbuf.hxx>
16 #include <libexslt/exslt.h>
17 #include <libxslt/transform.h>
18 #include <libxslt/xslt.h>
19 #include <libxslt/xsltutils.h>
32 OString sInputFileName
;
35 int extractTranslations()
37 PoOfstream
aPOStream( sOutputFile
, PoOfstream::APP
);
38 if (!aPOStream
.isOpen())
40 fprintf(stderr
, "cannot open %s\n", sOutputFile
.getStr());
46 OString sStyleSheet
= OString(getenv("SRC_ROOT")) + OString("/solenv/bin/uilangfilter.xslt");
48 xsltStylesheetPtr stylesheet
= xsltParseStylesheetFile ((const xmlChar
*)sStyleSheet
.getStr());
50 xmlDocPtr doc
= xmlParseFile(sInputFileName
.getStr());
52 xmlDocPtr res
= xsltApplyStylesheet(stylesheet
, doc
, NULL
);
54 for( xmlNodePtr nodeLevel1
= res
->children
; nodeLevel1
!= NULL
; nodeLevel1
= nodeLevel1
->next
)
56 for( xmlNodePtr nodeLevel2
= nodeLevel1
->children
; nodeLevel2
!= NULL
; nodeLevel2
= nodeLevel2
->next
)
58 if (nodeLevel2
->type
== XML_ELEMENT_NODE
)
60 std::vector
<OString
> vIDs
;
61 for(xmlAttrPtr attribute
= nodeLevel2
->properties
; attribute
!= NULL
; attribute
= attribute
->next
)
63 xmlChar
*content
= xmlNodeListGetString(res
, attribute
->children
, 1);
64 vIDs
.push_back(helper::xmlStrToOString(content
));
67 OString sText
= helper::UnQuotHTML(helper::xmlStrToOString(xmlNodeGetContent(nodeLevel2
)));
69 "Uiex", aPOStream
, sInputFileName
, vIDs
[0],
70 (vIDs
.size()>=2) ? vIDs
[1] : OString(),
71 (vIDs
.size()>=3) ? vIDs
[2] : OString(),
81 xsltFreeStylesheet(stylesheet
);
91 const MergeDataHashMap
&rMap
,
92 const OString
&rLanguage
,
93 const OString
&rDestinationFile
)
95 std::ofstream
aDestination(
96 rDestinationFile
.getStr(), std::ios_base::out
| std::ios_base::trunc
);
97 if (!aDestination
.is_open()) {
101 aDestination
<< "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
102 aDestination
<< "<t>\n";
104 for (MergeDataHashMap::const_iterator aI
= rMap
.begin(), aEnd
= rMap
.end(); aI
!= aEnd
; ++aI
)
106 if (aI
->second
->sGID
.isEmpty())
109 MergeEntrys
* pEntrys
= aI
->second
->GetMergeEntries();
111 pEntrys
->GetText( sOut
, STRING_TYP_TEXT
, rLanguage
);
116 aDestination
<< " <e "
117 << "g=\"" << aI
->second
->sGID
.getStr() << "\" "
118 << "i=\"" << aI
->second
->sLID
.getStr() << "\">"
119 << helper::QuotHTML(sOut
).getStr() << "</e>\n";
122 aDestination
<< "</t>";
123 aDestination
.close();
131 const OString
&rPOFile
,
132 const OString
&rSourceFile
,
133 const OString
&rDestinationDir
,
134 const OString
&rLanguage
)
137 bool bDestinationIsDir(false);
139 const OUString
aDestDir(OStringToOUString(rDestinationDir
, RTL_TEXTENCODING_UTF8
));
140 OUString aDestDirUrl
;
141 if (osl::FileBase::E_None
== osl::FileBase::getFileURLFromSystemPath(aDestDir
, aDestDirUrl
))
143 osl::DirectoryItem aTmp
;
144 if (osl::DirectoryItem::E_None
== osl::DirectoryItem::get(aDestDirUrl
, aTmp
))
146 osl::FileStatus
aDestinationStatus(osl_FileStatus_Mask_Type
);
147 if (osl::DirectoryItem::E_None
== aTmp
.getFileStatus(aDestinationStatus
))
148 bDestinationIsDir
= aDestinationStatus
.isDirectory();
152 if (!bDestinationIsDir
)
154 fprintf(stderr
, "%s must be a directory\n", rDestinationDir
.getStr());
159 MergeDataFile
aMergeDataFile( rPOFile
, rSourceFile
, sal_False
);
160 std::vector
<OString
> aLanguages
;
161 if( rLanguage
.equalsIgnoreAsciiCase("ALL") )
162 aLanguages
= aMergeDataFile
.GetLanguages();
164 aLanguages
.push_back(rLanguage
);
166 const MergeDataHashMap
& rMap
= aMergeDataFile
.getMap();
167 const OString
aDestinationDir(rDestinationDir
+ "/");
170 for(size_t n
= 0; n
< aLanguages
.size(); ++n
)
172 OString sCur
= aLanguages
[ n
];
173 if (sCur
.isEmpty() || sCur
.equalsIgnoreAsciiCaseL(RTL_CONSTASCII_STRINGPARAM("en-US")))
175 const OString
aDestinationFile(aDestinationDir
+ sCur
+ ".ui");
176 if (!lcl_MergeLang(rMap
, sCur
, aDestinationFile
))
183 SAL_IMPLEMENT_MAIN_WITH_ARGS(argc
, argv
)
187 common::HandledArgs aArgs
;
188 if ( !common::handleArguments(argc
, argv
, aArgs
) )
190 common::writeUsage("uiex","*.ui");
194 sInputFileName
= aArgs
.m_sInputFile
;
195 sOutputFile
= aArgs
.m_sOutputFile
;
197 if (!aArgs
.m_bMergeMode
)
199 nRetValue
= extractTranslations();
203 Merge(aArgs
.m_sMergeSrc
, sInputFileName
, sOutputFile
, aArgs
.m_sLanguage
);
209 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */