Skip to content
Browse files

Add support for <i18n> translation tag in .qsp and .qjs files.

Text between <i18n> and </i18n> will be run through QObject::tr()
before being processed by the scripting engine.  The values are
translated as the file is read in, so the translated values are
cached as part of the parsed script.

Translations are not yet enabled in mythbackend, and the HTML
setup webpages do not use the <i18n> tags yet, so there are not
yet any visible effects from this patch.

This modifies the binary API version, so make clean, etc..
  • Loading branch information...
1 parent 6cdd712 commit d9c00bdf8a93d7973f7eac52ee20370e98736266 @cpinkham cpinkham committed
View
2 mythtv/libs/libmythbase/mythversion.h
@@ -12,7 +12,7 @@
/// Update this whenever the plug-in API changes.
/// Including changes in the libmythbase, libmyth, libmythtv, libmythav* and
/// libmythui class methods used by plug-ins.
-#define MYTH_BINARY_VERSION "0.25.20110422-1"
+#define MYTH_BINARY_VERSION "0.25.20110425-1"
/** \brief Increment this whenever the MythTV network protocol changes.
*
View
59 mythtv/libs/libmythupnp/serverSideScripting.cpp
@@ -190,6 +190,7 @@ QString ServerSideScripting::CreateMethodFromFile( const QString &sFileName )
try
{
QTextStream stream( &scriptFile );
+ QString sTransBuffer;
sCode << "(function( os ) {\n";
@@ -197,7 +198,7 @@ QString ServerSideScripting::CreateMethodFromFile( const QString &sFileName )
{
QString sLine = stream.readLine();
- bInCode = ProcessLine( sCode, sLine, bInCode );
+ bInCode = ProcessLine( sCode, sLine, bInCode, sTransBuffer );
}
sCode << "})";
@@ -221,15 +222,65 @@ QString ServerSideScripting::CreateMethodFromFile( const QString &sFileName )
bool ServerSideScripting::ProcessLine( QTextStream &sCode,
QString &sLine,
- bool bInCode )
+ bool bInCode,
+ QString &sTransBuffer )
{
+ sLine = sLine.trimmed();
+
+ QString sLowerLine = sLine.toLower();
+
+ if (!sTransBuffer.isEmpty())
+ {
+ int nEndTransPos = sLowerLine.indexOf("</i18n>");
+
+ if (nEndTransPos == -1)
+ {
+ sTransBuffer.append(" ");
+ sTransBuffer.append(sLine);
+ return bInCode;
+ }
+
+ if (nEndTransPos > 0)
+ sTransBuffer.append(" ");
+
+ sTransBuffer.append(sLine.left(nEndTransPos).trimmed());
+ QString trStr =
+ QObject::tr(sTransBuffer.trimmed().toLocal8Bit().data());
+ trStr.replace( '"', "\\\"" );
+ sCode << "os.write( \"" << trStr << "\" );\n";
+ sTransBuffer = "";
+
+ if (nEndTransPos == (sLine.length() - 7))
+ return bInCode;
+
+ sLine = sLine.right(sLine.length() - (nEndTransPos + 7));
+ }
+
+ int nStartTransPos = sLowerLine.indexOf("<i18n>");
+ if (nStartTransPos != -1)
+ {
+ int nEndTransPos = sLowerLine.indexOf("</i18n>");
+ if (nEndTransPos != -1)
+ {
+ QString patStr = sLine.mid(nStartTransPos,
+ (nEndTransPos + 7 - nStartTransPos));
+ QString repStr = patStr.mid(6, patStr.length() - 13).trimmed();
+ sLine.replace(patStr, QObject::tr(repStr.toLocal8Bit().data()));
+ return ProcessLine(sCode, sLine, bInCode, sTransBuffer);
+ }
+ else
+ {
+ sTransBuffer = " ";
+ sTransBuffer.append(sLine.mid(nStartTransPos + 6).trimmed());
+ sLine = sLine.left(nStartTransPos);
+ }
+ }
+
int nStartPos = 0;
int nEndPos = 0;
int nMatchPos = 0;
bool bMatchFound = false;
- sLine = sLine.trimmed();
-
QString sExpecting = bInCode ? "%>" : "<%";
bool bNewLine = !(sLine.startsWith( sExpecting ));
View
3 mythtv/libs/libmythupnp/serverSideScripting.h
@@ -78,7 +78,8 @@ class UPNP_PUBLIC ServerSideScripting
bool ProcessLine ( QTextStream &sCode,
QString &sLine,
- bool bInCode );
+ bool bInCode,
+ QString &sTransBuffer );
};

0 comments on commit d9c00bd

Please sign in to comment.
Something went wrong with that request. Please try again.