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 (reinterpret_cast<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 g=\"" << aI
->second
->sGID
.getStr() << "\" i=\""
117 << aI
->second
->sLID
.getStr() << "\">"
118 << helper::QuotHTML(sOut
).getStr() << "</e>\n";
121 aDestination
<< "</t>";
122 aDestination
.close();
130 const OString
&rPOFile
,
131 const OString
&rSourceFile
,
132 const OString
&rDestinationDir
,
133 const OString
&rLanguage
)
136 bool bDestinationIsDir(false);
138 const OUString
aDestDir(OStringToOUString(rDestinationDir
, RTL_TEXTENCODING_UTF8
));
139 OUString aDestDirUrl
;
140 if (osl::FileBase::E_None
== osl::FileBase::getFileURLFromSystemPath(aDestDir
, aDestDirUrl
))
142 osl::DirectoryItem aTmp
;
143 if (osl::DirectoryItem::E_None
== osl::DirectoryItem::get(aDestDirUrl
, aTmp
))
145 osl::FileStatus
aDestinationStatus(osl_FileStatus_Mask_Type
);
146 if (osl::DirectoryItem::E_None
== aTmp
.getFileStatus(aDestinationStatus
))
147 bDestinationIsDir
= aDestinationStatus
.isDirectory();
151 if (!bDestinationIsDir
)
153 fprintf(stderr
, "%s must be a directory\n", rDestinationDir
.getStr());
158 MergeDataFile
aMergeDataFile( rPOFile
, rSourceFile
, false );
159 std::vector
<OString
> aLanguages
;
160 if( rLanguage
.equalsIgnoreAsciiCase("ALL") )
161 aLanguages
= aMergeDataFile
.GetLanguages();
163 aLanguages
.push_back(rLanguage
);
165 const MergeDataHashMap
& rMap
= aMergeDataFile
.getMap();
166 const OString
aDestinationDir(rDestinationDir
+ "/");
169 for(size_t n
= 0; n
< aLanguages
.size(); ++n
)
171 OString sCur
= aLanguages
[ n
];
172 if (sCur
.isEmpty() || sCur
.equalsIgnoreAsciiCase("en-US"))
174 const OString
aDestinationFile(aDestinationDir
+ sCur
+ ".ui");
175 if (!lcl_MergeLang(rMap
, sCur
, aDestinationFile
))
182 SAL_IMPLEMENT_MAIN_WITH_ARGS(argc
, argv
)
186 common::HandledArgs aArgs
;
187 if ( !common::handleArguments(argc
, argv
, aArgs
) )
189 common::writeUsage("uiex","*.ui");
193 sInputFileName
= aArgs
.m_sInputFile
;
194 sOutputFile
= aArgs
.m_sOutputFile
;
196 if (!aArgs
.m_bMergeMode
)
198 nRetValue
= extractTranslations();
202 Merge(aArgs
.m_sMergeSrc
, sInputFileName
, sOutputFile
, aArgs
.m_sLanguage
);
208 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */