Skip to content

Commit 2571364

Browse files
committed
Better multiline po handling
1 parent 57afd52 commit 2571364

File tree

4 files changed

+46
-13
lines changed

4 files changed

+46
-13
lines changed

default.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
testdebug = False # TODO: check
2323
testTasks = False # TODO: check
2424
branch = 'master'
25-
build = '1008'
25+
build = '1009'
2626

2727
from resources.lib.utils.debugger import startdebugger
2828

@@ -66,7 +66,7 @@ def __init__(self):
6666

6767
def onSettingsChanged(self):
6868
dialog = xbmcgui.Dialog()
69-
msg = _('If improperly implemented, running user tasks can damage your system.\nThe user assumes all risks and liability for running tasks.').split('\\n')
69+
msg = _('If improperly implemented, running user tasks can damage your system.\nThe user assumes all risks and liability for running tasks.').split('\n')
7070
dialog.ok(_('Kodi Callbacks'), line1=msg[0], line2=msg[1])
7171
log(msg=_('Settings change detected - attempting to restart'))
7272
abortall()

resources/language/English/strings.po

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,14 @@ msgid "Command for Task %s, Event %s completed succesfully!"
123123
msgstr ""
124124

125125
msgctxt "#32025"
126-
msgid "\nThe following message was returned: %s"
126+
msgid "\n"
127+
"The following message was returned: %s"
127128
msgstr ""
128129

129130
msgctxt "#32026"
130-
msgid "ERROR encountered for Task %s, Event %s\nERROR mesage: %s"
131+
msgid ""
132+
"ERROR encountered for Task %s, Event %s\n"
133+
"ERROR mesage: %s"
131134
msgstr ""
132135

133136
msgctxt "#32027"
@@ -807,7 +810,9 @@ msgid "Watchdog Startup could not load pickle"
807810
msgstr ""
808811

809812
msgctxt "#32196"
810-
msgid "A new version of %s is available\nDownload and install?"
813+
msgid ""
814+
"A new version of %s is available\n"
815+
"Download and install?"
811816
msgstr ""
812817

813818
msgctxt "#32197"
@@ -827,7 +832,8 @@ msgid "New version installed"
827832
msgstr ""
828833

829834
msgctxt "#32201"
830-
msgid "\nPrevious installation backed up"
835+
msgid "\n"
836+
"Previous installation backed up"
831837
msgstr ""
832838

833839
msgctxt "#32202"
@@ -839,7 +845,9 @@ msgid "All files are current"
839845
msgstr ""
840846

841847
msgctxt "#32204"
842-
msgid "Could not find addon.xml\nInstallation aborted"
848+
msgid ""
849+
"Could not find addon.xml\n"
850+
"Installation aborted"
843851
msgstr ""
844852

845853
msgctxt "#32205"
@@ -1219,6 +1227,8 @@ msgid "No actions run for this addon from Programs"
12191227
msgstr ""
12201228

12211229
msgctxt "#32299"
1222-
msgid "If improperly implemented, running user tasks can damage your system.\nThe user assumes all risks and liability for running tasks."
1230+
msgid ""
1231+
"If improperly implemented, running user tasks can damage your system.\n"
1232+
"The user assumes all risks and liability for running tasks."
12231233
msgstr ""
12241234

resources/lib/utils/poutil.py

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ def _(self, strToId, update=False):
6666
self.getLocalizedString(strToId, update)
6767

6868
def getLocalizedString(self, strToId, update=False):
69-
strToId = strToId.replace('\n', '\\n')
7069
idFound, strid = self.podict.has_msgid(strToId)
7170
if idFound:
7271
if self.podict.savethread.is_alive():
@@ -172,7 +171,12 @@ def read_from_file(self, url):
172171
str_msgctxt = t[0][2:7]
173172
i += 1
174173
line2 = poin[i]
175-
str_msgid = self.remsgid.findall(line2)[0]
174+
str_msgid = ''
175+
while not line2.startswith('msgstr'):
176+
str_msgid += self.remsgid.findall(line2)[0]
177+
i += 1
178+
line2 = poin[i]
179+
str_msgid = str_msgid.decode('unicode_escape')
176180
self.dict_msgctxt[str_msgctxt] = str_msgid
177181
self.dict_msgid[str_msgid] = str_msgctxt
178182
self.chkdict[str_msgctxt] = False
@@ -253,7 +257,7 @@ def write_po_header(fo):
253257
def write_to_po(fileobject, int_num, str_msg):
254258
w = r'"#' + str(int_num) + r'"'
255259
fileobject.write('msgctxt ' + w + '\n')
256-
fileobject.write('msgid ' + r'"' + str_msg + r'"' + '\n')
260+
fileobject.write(splitstring(str_msg))
257261
fileobject.write('msgstr ' + r'""' + '\n')
258262
fileobject.write('\n')
259263

@@ -270,6 +274,25 @@ def createreport(self):
270274
ret = '\n '.join(reportpo)
271275
return ret
272276

277+
def splitstring(s):
278+
ret = []
279+
s = s.replace('\n', '~@\n')
280+
split = s.split('\n')
281+
for i in xrange(0, len(split)):
282+
split[i] = split[i].replace('~@', '\n').encode('unicode_escape')
283+
if i == 0:
284+
if (len(split) == 2 and split[i+1] == '') or split[i] == '\\n' or len(split) == 1:
285+
ret.append('msgid "%s"\n' % split[i])
286+
else:
287+
ret.append('msgid ""\n')
288+
ret.append('"%s"\n' % split[i])
289+
elif i == len(split) - 1:
290+
if split[i] != '':
291+
ret.append('"%s"\n' % split[i])
292+
else:
293+
ret.append('"%s"\n' % split[i])
294+
ret = ''.join(ret)
295+
return ret
273296

274297
class UpdatePo(object):
275298

@@ -331,7 +354,7 @@ def scanPyFilesForStrings(self):
331354
def updateStringsPo(self):
332355
lstrings = self.scanPyFilesForStrings()
333356
for s in lstrings:
334-
found, strid = self.podict.has_msgid(s)
357+
found, strid = self.podict.has_msgid(s.decode('unicode_escape'))
335358
if found is False:
336359
self.podict.addentry(strid, s)
337360
self.podict.write_to_file(self.current_working_English_strings_po)

timestamp.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"resources/lib/tests/__init__.py": "2016-01-14T15:24:21Z", "resources/lib/watchdog/observers/polling.py": "2016-01-17T07:10:59Z", "resources/__init__.py": "2016-01-14T15:24:21Z", "resources/lib/publishers/__init__.py": "2016-01-14T15:24:21Z", "resources/lib/pathtools/README.rst": "2016-01-25T10:11:22Z", "resources/lib/taskExample.py": "2016-03-07T15:48:16Z", "resources/lib/pathtools/README": "2016-01-25T10:11:22Z", "resources/skins/Default/720p/DialogTextBox.xml": "2016-01-14T15:24:21Z", "resources/lib/watchdog/utils/delayed_queue.py": "2016-01-17T07:10:59Z", "resources/lib/kodisettings/generate_xml.py": "2016-03-31T17:27:35Z", "resources/lib/watchdog/watchmedo.py": "2016-01-17T07:10:59Z", ".gitignore": "2016-04-04T07:13:26Z", "resources/lib/tests/tstScript.sh": "2016-02-27T07:40:29Z", "default.py": "2016-04-20T16:19:39Z", "resources/lib/watchdog/LICENSE.txt": "2016-01-25T10:10:48Z", "resources/lib/watchdog/utils/event_backport.py": "2016-01-17T07:10:59Z", "resources/lib/watchdog/utils/compat.py": "2016-01-17T07:10:59Z", "resources/lib/publishers/watchdogStartup.py": "2016-03-29T14:16:26Z", "resources/lib/pathtools/AUTHORS": "2016-01-25T10:11:22Z", "resources/lib/tasks/taskScript.py": "2016-03-06T11:30:01Z", "resources/lib/tasks/__init__.py": "2016-01-14T15:24:21Z", "resources/lib/publishers/schedule.py": "2016-04-16T05:41:18Z", "resources/lib/tests/testTasks.py": "2016-03-29T14:16:28Z", "resources/lib/kodisettings/struct.py": "2016-04-04T07:13:25Z", "icon.png": "2016-03-27T10:13:37Z", "resources/lib/watchdog/observers/__init__.py": "2016-01-19T05:48:22Z", "resources/lib/utils/selector.py": "2016-03-10T17:12:51Z", "resources/language/English/strings.po": "2016-04-20T16:20:57Z", "resources/lib/pubsub.py": "2016-04-04T07:13:25Z", "resources/lib/watchdog/observers/fsevents.py": "2016-01-17T07:10:59Z", "resources/lib/tasks/taskHttp.py": "2016-04-09T09:38:56Z", "resources/lib/events.py": "2016-04-02T09:09:38Z", "resources/lib/subscriberfactory.py": "2016-02-26T13:45:16Z", "resources/lib/watchdog/AUTHORS": "2016-01-25T10:10:48Z", "resources/lib/utils/detectPath.py": "2016-02-27T06:41:25Z", "resources/lib/publishers/dummy.py": "2016-03-29T14:16:26Z", "resources/lib/kodilogging.py": "2016-04-04T07:13:26Z", "resources/lib/pathtools/__init__.py": "2016-01-17T07:10:43Z", "resources/lib/watchdog/observers/inotify_c.py": "2016-01-17T07:10:59Z", "resources/lib/watchdog/tricks/__init__.py": "2016-01-17T07:10:59Z", "script.py": "2016-04-14T06:35:41Z", "resources/settings.xml": "2016-04-20T16:20:57Z", "resources/lib/watchdog/utils/dirsnapshot.py": "2016-02-01T11:27:31Z", "resources/lib/watchdog/utils/bricks.py": "2016-01-17T07:10:59Z", "resources/lib/tasks/taskPython.py": "2016-03-06T11:30:01Z", "resources/lib/publishers/loop.py": "2016-03-29T14:16:26Z", "resources/lib/kodisettings/__init__.py": "2016-03-06T11:30:01Z", "timestamp.json": "2016-04-20T16:21:58Z", "testme.py": "2016-01-27T17:12:23Z", "resources/lib/watchdog/version.py": "2016-01-17T07:10:59Z", "resources/lib/utils/updateaddon.py": "2016-04-04T07:13:26Z", "resources/lib/watchdog/utils/unicode_paths.py": "2016-01-17T07:10:59Z", "resources/lib/publisherfactory.py": "2016-03-24T17:00:38Z", "resources/lib/schedule/__init__.py": "2016-02-26T13:45:25Z", "resources/lib/watchdog/__init__.py": "2016-01-17T07:10:59Z", "addon.xml": "2016-04-14T06:35:41Z", "resources/lib/watchdog/utils/platform.py": "2016-01-17T07:10:59Z", "resources/lib/tasks/taskBuiltin.py": "2016-03-06T11:30:01Z", "resources/lib/watchdog/utils/importlib2.py": "2016-01-17T07:10:59Z", "README.md": "2016-02-01T07:40:27Z", "resources/lib/pathtools/path.py": "2016-01-17T07:10:43Z", "resources/lib/tests/direct_test.py": "2016-04-09T09:38:56Z", "resources/lib/pathtools/LICENSE.txt": "2016-01-25T10:08:08Z", "resources/lib/watchdog/utils/echo.py": "2016-01-17T07:10:59Z", "resources/lib/pathtools/patterns.py": "2016-01-17T07:10:43Z", "resources/lib/publishers/monitor.py": "2016-04-04T07:13:26Z", "resources/lib/watchdog/observers/fsevents2.py": "2016-01-17T07:10:59Z", "resources/lib/watchdog/observers/kqueue.py": "2016-01-17T07:10:59Z", "resources/lib/watchdog/observers/read_directory_changes.py": "2016-01-17T07:10:59Z", "resources/lib/tests/tstScript.bat": "2016-02-27T07:24:43Z", "resources/lib/utils/__init__.py": "2016-01-24T07:36:06Z", "resources/lib/watchdog/utils/decorators.py": "2016-01-17T07:10:59Z", "resources/lib/watchdog/observers/inotify.py": "2016-01-17T07:10:59Z", "resources/lib/utils/poutil.py": "2016-04-14T06:35:41Z", "resources/lib/publishers/player.py": "2016-04-16T05:41:18Z", "LICENSE.txt": "2016-01-25T10:16:54Z", "resources/lib/watchdog/observers/winapi.py": "2016-01-17T07:10:59Z", "resources/lib/watchdog/events.py": "2016-01-17T07:10:59Z", "changelog.txt": "2016-03-27T10:13:57Z", "resources/lib/watchdog/utils/__init__.py": "2016-02-14T17:00:24Z", "resources/lib/tests/testPublishers.py": "2016-03-27T08:38:33Z", "resources/lib/taskABC.py": "2016-03-29T14:16:28Z", "resources/lib/watchdog/README.rst": "2016-01-25T10:10:48Z", "resources/lib/pathtools/version.py": "2016-01-17T07:10:43Z", "resources/lib/publishers/log.py": "2016-03-15T07:12:35Z", "resources/lib/utils/copyToDir.py": "2016-04-04T07:13:26Z", "resources/lib/watchdog/observers/inotify_buffer.py": "2016-01-17T07:10:59Z", "fanart.jpg": "2016-02-26T13:45:25Z", "resources/lib/utils/kodipathtools.py": "2016-03-27T10:13:57Z", "resources/lib/utils/debugger.py": "2016-04-02T08:14:50Z", "resources/lib/watchdog/utils/win32stat.py": "2016-01-17T07:10:59Z", "resources/lib/tasks/taskJson.py": "2016-03-11T06:45:04Z", "resources/lib/publishers/watchdog.py": "2016-03-29T14:16:26Z", "resources/lib/dialogtb.py": "2016-04-04T07:13:26Z", "resources/lib/settings.py": "2016-04-04T07:13:26Z", "restartaddon.py": "2016-02-13T15:07:18Z", "resources/lib/watchdog/observers/api.py": "2016-01-17T07:10:59Z", "resources/lib/tests/tstPythonGlobal.py": "2016-04-03T08:08:06Z", "resources/lib/__init__.py": "2016-04-09T09:38:56Z", ".gitattributes": "2016-04-04T07:13:26Z", "resources/lib/watchdog/COPYING": "2016-01-25T10:10:48Z"}
1+
{"resources/lib/tests/__init__.py": "2016-01-14T15:24:21Z", "resources/lib/watchdog/observers/polling.py": "2016-01-17T07:10:59Z", "resources/__init__.py": "2016-01-14T15:24:21Z", "resources/lib/publishers/__init__.py": "2016-01-14T15:24:21Z", "resources/lib/pathtools/README.rst": "2016-01-25T10:11:22Z", "resources/lib/taskExample.py": "2016-03-07T15:48:16Z", "resources/lib/pathtools/README": "2016-01-25T10:11:22Z", "resources/skins/Default/720p/DialogTextBox.xml": "2016-01-14T15:24:21Z", "resources/lib/watchdog/utils/delayed_queue.py": "2016-01-17T07:10:59Z", "resources/lib/kodisettings/generate_xml.py": "2016-03-31T17:27:35Z", "resources/lib/watchdog/watchmedo.py": "2016-01-17T07:10:59Z", ".gitignore": "2016-04-04T07:13:26Z", "resources/lib/tests/tstScript.sh": "2016-02-27T07:40:29Z", "default.py": "2016-04-28T08:42:29Z", "resources/lib/watchdog/LICENSE.txt": "2016-01-25T10:10:48Z", "resources/lib/watchdog/utils/event_backport.py": "2016-01-17T07:10:59Z", "resources/lib/watchdog/utils/compat.py": "2016-01-17T07:10:59Z", "resources/lib/publishers/watchdogStartup.py": "2016-03-29T14:16:26Z", "resources/lib/pathtools/AUTHORS": "2016-01-25T10:11:22Z", "resources/lib/tasks/taskScript.py": "2016-03-06T11:30:01Z", "resources/lib/tasks/__init__.py": "2016-01-14T15:24:21Z", "resources/lib/publishers/schedule.py": "2016-04-16T05:41:18Z", "resources/lib/tests/testTasks.py": "2016-03-29T14:16:28Z", "resources/lib/kodisettings/struct.py": "2016-04-04T07:13:25Z", "icon.png": "2016-03-27T10:13:37Z", "resources/lib/watchdog/observers/__init__.py": "2016-01-19T05:48:22Z", "resources/lib/utils/selector.py": "2016-03-10T17:12:51Z", "resources/language/English/strings.po": "2016-04-28T08:42:32Z", "resources/lib/pubsub.py": "2016-04-04T07:13:25Z", "resources/lib/watchdog/observers/fsevents.py": "2016-01-17T07:10:59Z", "resources/lib/tasks/taskHttp.py": "2016-04-09T09:38:56Z", "resources/lib/events.py": "2016-04-02T09:09:38Z", "resources/lib/subscriberfactory.py": "2016-02-26T13:45:16Z", "resources/lib/watchdog/AUTHORS": "2016-01-25T10:10:48Z", "resources/lib/utils/detectPath.py": "2016-02-27T06:41:25Z", "resources/lib/publishers/dummy.py": "2016-03-29T14:16:26Z", "resources/lib/kodilogging.py": "2016-04-04T07:13:26Z", "resources/lib/pathtools/__init__.py": "2016-01-17T07:10:43Z", "resources/lib/watchdog/observers/inotify_c.py": "2016-01-17T07:10:59Z", "resources/lib/watchdog/tricks/__init__.py": "2016-01-17T07:10:59Z", "script.py": "2016-04-14T06:35:41Z", "resources/settings.xml": "2016-04-28T08:42:31Z", "resources/lib/watchdog/utils/dirsnapshot.py": "2016-02-01T11:27:31Z", "resources/lib/watchdog/utils/bricks.py": "2016-01-17T07:10:59Z", "resources/lib/tasks/taskPython.py": "2016-03-06T11:30:01Z", "resources/lib/publishers/loop.py": "2016-03-29T14:16:26Z", "resources/lib/kodisettings/__init__.py": "2016-03-06T11:30:01Z", "timestamp.json": "2016-04-28T08:42:38Z", "testme.py": "2016-01-27T17:12:23Z", "resources/lib/watchdog/version.py": "2016-01-17T07:10:59Z", "resources/lib/utils/updateaddon.py": "2016-04-04T07:13:26Z", "resources/lib/watchdog/utils/unicode_paths.py": "2016-01-17T07:10:59Z", "resources/lib/publisherfactory.py": "2016-03-24T17:00:38Z", "resources/lib/schedule/__init__.py": "2016-02-26T13:45:25Z", "resources/lib/watchdog/__init__.py": "2016-01-17T07:10:59Z", "addon.xml": "2016-04-21T06:34:54Z", "resources/lib/watchdog/utils/platform.py": "2016-01-17T07:10:59Z", "resources/lib/tasks/taskBuiltin.py": "2016-03-06T11:30:01Z", "resources/lib/watchdog/utils/importlib2.py": "2016-01-17T07:10:59Z", "README.md": "2016-02-01T07:40:27Z", "resources/lib/pathtools/path.py": "2016-01-17T07:10:43Z", "resources/lib/tests/direct_test.py": "2016-04-09T09:38:56Z", "resources/lib/pathtools/LICENSE.txt": "2016-01-25T10:08:08Z", "resources/lib/watchdog/utils/echo.py": "2016-01-17T07:10:59Z", "resources/lib/pathtools/patterns.py": "2016-01-17T07:10:43Z", "resources/lib/publishers/monitor.py": "2016-04-04T07:13:26Z", "resources/lib/watchdog/observers/fsevents2.py": "2016-01-17T07:10:59Z", "resources/lib/watchdog/observers/kqueue.py": "2016-01-17T07:10:59Z", "resources/lib/watchdog/observers/read_directory_changes.py": "2016-01-17T07:10:59Z", "resources/lib/tests/tstScript.bat": "2016-02-27T07:24:43Z", "resources/lib/utils/__init__.py": "2016-01-24T07:36:06Z", "resources/lib/watchdog/utils/decorators.py": "2016-01-17T07:10:59Z", "resources/lib/watchdog/observers/inotify.py": "2016-01-17T07:10:59Z", "resources/lib/utils/poutil.py": "2016-04-27T09:35:15Z", "resources/lib/publishers/player.py": "2016-04-16T05:41:18Z", "LICENSE.txt": "2016-01-25T10:16:54Z", "resources/lib/watchdog/observers/winapi.py": "2016-01-17T07:10:59Z", "resources/lib/watchdog/events.py": "2016-01-17T07:10:59Z", "changelog.txt": "2016-03-27T10:13:57Z", "resources/lib/watchdog/utils/__init__.py": "2016-02-14T17:00:24Z", "resources/lib/tests/testPublishers.py": "2016-03-27T08:38:33Z", "resources/lib/taskABC.py": "2016-03-29T14:16:28Z", "resources/lib/watchdog/README.rst": "2016-01-25T10:10:48Z", "resources/lib/pathtools/version.py": "2016-01-17T07:10:43Z", "resources/lib/publishers/log.py": "2016-03-15T07:12:35Z", "resources/lib/utils/copyToDir.py": "2016-04-04T07:13:26Z", "resources/lib/watchdog/observers/inotify_buffer.py": "2016-01-17T07:10:59Z", "fanart.jpg": "2016-02-26T13:45:25Z", "resources/lib/utils/kodipathtools.py": "2016-03-27T10:13:57Z", "resources/lib/utils/debugger.py": "2016-04-02T08:14:50Z", "resources/lib/watchdog/utils/win32stat.py": "2016-01-17T07:10:59Z", "resources/lib/tasks/taskJson.py": "2016-03-11T06:45:04Z", "resources/lib/publishers/watchdog.py": "2016-03-29T14:16:26Z", "resources/lib/dialogtb.py": "2016-04-04T07:13:26Z", "resources/lib/settings.py": "2016-04-04T07:13:26Z", "restartaddon.py": "2016-02-13T15:07:18Z", "resources/lib/watchdog/observers/api.py": "2016-01-17T07:10:59Z", "resources/lib/tests/tstPythonGlobal.py": "2016-04-03T08:08:06Z", "resources/lib/__init__.py": "2016-04-09T09:38:56Z", ".gitattributes": "2016-04-04T07:13:26Z", "resources/lib/watchdog/COPYING": "2016-01-25T10:10:48Z"}

0 commit comments

Comments
 (0)