Skip to content
KenV99 edited this page Jul 8, 2014 · 5 revisions

Table of Contents

Introduction

The main purpose of this python script is to make working with localized strings and your main strings.po file easier when creating addons for XBMC. The user can mark lines with hard coded strings that need to be localized by ending with a comment (# @@). The enclosed script will scan through the working directory of the script and locate all of the .py files and scan through them, replacing the hard coded strings with a standard XBMC call for localization (i.e. __language__(32001)) and create an entry in the English/strings.po file for that hard coded string. It can also scan through your settings.xml and find any hard-coded label= or lvalues= tags and also replace these with localized strings. Optionally, it will then include in a trailing line comment the original text so that the code remains readable.

Features

  • Scans through all python files recursively in a directory and replaces marked hard coded strings with language calls.
  • Optionally adds an inline comment with the original text.
  • Works with existing English/strings.po file and will add comments to existing language calls.
  • Will reuse strings to prevent duplication.
  • Users can exclude .py files and/or directories from scanning.
  • Will not alter original files, all new files are placed in a subdirectory called 'localized' (including the strings.po file.
  • In the vast majority of cases, it identifies nested and/or escaped single and double quotes.
  • Scan through settings.xml file and replace hardcoded strings and comment with replaced strings.
  • Checks for the presence of a localized string function in python files using localization.
  • Creates a report showing the presence of any localization codes that are not defined in the strings.po file
  • Creates a report showing any unused strings in the po file.

Installation

Download the zipped file from: https://github.com/KenV99/poxbmc Place the file poxbmc.py in the root directory of your addon. This is needed, at least the way the defaults are set up so that it can locate the /resources/language/English/strings.po file, but that can be changed. The options are implemented by editing the poxbmc.py file directory. They are at the beginning of the file and are self-explanatory.

Go through your python files and mark any lines that need localized strings by placing '# @@' without the quotes at the end of line. Go ahead and optionally using proper PEP-8 styling and put two spaces before the # so that you don't have to stare at the IDE telling you that you are out of style.

First, check the options at the beginning of the poxbmc.py file. Make sure you put it any other files or directories you may want to exclude. By default it excludes itself and the localized subdirectory. Then run it either from your IDE or the command line. Currently there are no command line options.

Once it completes, look through the files in the subdirectory '/localized' and make sure things went as expected. If you are happy with the results, then do whatever is best with whatever local IDE/CVS program you are using to replace the non-localized files with the new ones.

A file called report.txt is also generated in the ./localized/ directory which describes any errors or anomalies encountered.

Limitations

  • Multi line strings in triple quotes are ignored.
  • If you are doing fancy, complicated manipulation of strings that need to be localized, you may encounter issues.
  • In rare cases, single quoted strings with unescaped interior double quotes may be erroneously misinterpreted.
  • It does not organize the strings.po file into categories of specific types of strings.
  • It does not generate or use information from localized po files other than English.

FAQs

Clone this wiki locally