Plugin localisation and internatinalization

i18n and L10n for the experts
Hi,

I've start my first dev yesterday and congratulation : your framework is really easy to use !
I've some questions about localization and internationalization :

1 - My plugin doesn't load when I used French special characters like "éè" in AddPrefixHandler or MediaContainer (I want to use "Allociné"). Is this a restriction of the current framework or do I have to add special code or function in python to use this type of character in strings

2 - Is their a way to have localizable preferences for a plugin. I don't find how to process with the "DefaultPrefs.json" file ?

I’m blocked with charset and encode/decode stuff !



I start with


PLUGIN_URL_BA_ANEPASMANQUER			= "http://rss.allocine.fr/ac/bandesannonces/anepasmanquer"<br />
....<br />
fluxXML = XML.ElementFromURL(PLUGIN_URL_BA_ANEPASMANQUER, encoding="iso-8859-1")


I've to add the encoding attribute to avoid an error like "UnicodeDecodeError: 'utf8' codec can't decode bytes in position 446-448: invalid data"

then

for c in fluxXML.xpath("//item"):<br />
		Log("c %s" % (lxml.etree.tostring(c, pretty_print=True)))<br />
		title = c.find('title').text.encode("utf-8")<br />
		Log("title %s" % (title))<br />
		thumb = c.find('enclosure').get('url')<br />
		Log("thumb %s" % (thumb))<br />
		url = c.find('link').text.encode("utf-8")<br />
		Log("url %s" % (url))<br />
		dir.Append(VideoItem(url, title=title, thumb=thumb))



The first Log show the data from one and I find in it : "Toy Story 3 - Teaser 1 (Anglais sous-titr& #195;& #169;)" (I've add a space between & and # to avoid a convertion in the post editor)
Notice the utf8 code for "é" character

But when I use the command "title = c.find('title').text.encode("utf-8")", the next log show "title Toy Story 3 - Teaser 1 (Anglais sous-titré)".
If I don't use the encode I've got an error !

Last when I return the dir object I've the following error :
"UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 41: ordinal not in range(128)"

Is somebody can help me ?

Sorry I do not have an answer for you but I do run in exactly the same problem when trying to parse XML files from the france2 website. I poked around a bit and the only things I could find was to do an decode(“Latin-1”).encode(“utf-8”) and that seemed to get me a bit further but eventually the error “cannot decode byte 0xc3” creeps up. Just sharing your pain …

I18N and encodings is hard in general, and I’m not sure that Python isn’t making it a bit harder than it needs to be.



In AddPrefixHandler or MediaContainer, do this: “Allociné”.decode(‘utf-8’) and put this at the top of your file:



# -*- coding: utf-8 -*-



That should solve that specific problem. The decode/encode tricks of the last reply can help too, as can specifying
errors='ignore' after the encoding=...

Hope that helps!

The fight with character encodings is going on behind the scenes, hopefully we should be able to make the framework handle things more gracefully :)

With regard to localized preferences, the label you specify in DefaultPrefs.json gets passed to the Locale module before being returned to Plex - if it's a vaild key, the localized string will be returned from the current strings file (e.g. Contents/Strings/fr.json). If not, the provided text will be used.

Thanks to all



I succeed in using French special characters.



1 - The Elan’s solution works to have an accent in the Plugin title.

2 - I succeed in using unicode object to avoid Plugin crash. Complicated to explain, you’ll can see the solution in the “Allociné” plugin sources when it will be release. To give some clues, Plex framework seems to manage well unicode string decoded in utf-8 but don’t forget to encode your unicode string before using it in Logs.

3 - The preference seems to be localizable. I haven’t try yet.



Now I just have to find why my video stream doesn’t play, and you’ll have another french plugin.

Hi,



I’ve start a list on the French forum with French speaking plugins. I’ve identified English plugins which are giving access to French contents : YouTube and Pisacca. I’ve already done the translation of the string file for Picassa. YouTube doesn’t seem to use this type of file. Is it planned ?



I can help if needed.



I don't succed in making this to work. In the "Picasa web Album " plugin I add this in the fr.json file :
[codebox]// Preferences
"Google/Picasa Username" : "Identifiant Google/Picasa",
"Google/Picasa Password" : "Mot de passe Google/Picasa",
"Show my private albums" : "Afficher mes albums privés",
"Show summary information on photographs" : "Afficher les résumés des photographes"[/codebox]


The defaultPrefs.json is
[codebox][
{
"id" : "username",
"type" : "text",
"label" : "Google/Picasa Username",
},
{
"id" : "password",
"type" : "text",
"label" : "Google/Picasa Password",
"option" : "hidden"
},
{
"id" : "showprivatealbums",
"type" : "bool",
"label" : "Show my private albums"
},
{
"id" : "showphotosummary",
"type" : "bool",
"label" : "Show summary information on photographs"
}
][/codebox]

And when I use the plugin, menu are in French but preferences are with the original text.
Any idea ?

I think you’d need to pass the id in on the left, like so:



"username" : "Identifiant Google/Picasa"

I’ve tried this too but same results :frowning:

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.