libreoffice/wizards-create-temlates-with-python-2.6.diff
2013-05-14 15:51:01 +00:00

66 lines
2.3 KiB
Diff

From 8a6be8341d0a962d1ec384440ece523607c8b1d5 Mon Sep 17 00:00:00 2001
From: Petr Mladek <pmladek@suse.cz>
Date: Tue, 14 May 2013 11:25:49 +0200
Subject: [PATCH] allow to create Letter and Fax templates with python 2.6
The localized file type desciptions have non-ascii characters.
The "str" type acceppts only "ascii" characters in python-2.6,
The string has to be encoded according to the system locale,
otherwise it is broken in non-UTF-* locales.
Change-Id: I0a138f10ec7c2665c0700918f671fbd5eb674bf6
---
wizards/com/sun/star/wizards/common/SystemDialog.py | 21 ++++++++++++++++++++-
1 file changed, 20 insertions(+), 1 deletion(-)
diff --git a/wizards/com/sun/star/wizards/common/SystemDialog.py b/wizards/com/sun/star/wizards/common/SystemDialog.py
index ab9b463..aa3426a 100644
--- a/wizards/com/sun/star/wizards/common/SystemDialog.py
+++ b/wizards/com/sun/star/wizards/common/SystemDialog.py
@@ -15,6 +15,7 @@
# except in compliance with the License. You may obtain a copy of
# the License at http://www.apache.org/licenses/LICENSE-2.0 .
#
+import locale
import traceback
from .Desktop import Desktop
@@ -139,6 +140,24 @@ class SystemDialog(object):
traceback.print_exc()
'''
+ The original string is in the system encoding but str accepts only "ascii" in python 2.6
+ This hack is not needed with python-3.0
+ '''
+ def createStr(self, sString):
+ try:
+ strString = str(sString)
+
+ except:
+ try:
+ sCodeSet = locale.nl_langinfo(locale.CODESET)
+ except:
+ sCodeSet = "utf-8"
+
+ strString = str(sString.encode(sCodeSet))
+
+ return strString
+
+ '''
note the result should go through conversion of the product name.
@param filterName
@return the UI localized name of the given filter name.
@@ -152,7 +171,7 @@ class SystemDialog(object):
xPropertyValue = list(oObject)
for i in xPropertyValue:
if i is not None and i.Name == "UIName":
- return str(i.Value).replace("%productname%", "LibreOffice")
+ return self.createStr(i.Value).replace("%productname%", "LibreOffice")
raise NullPointerException(
"UIName property not found for Filter " + filterName);
--
1.8.1.3