Missing or inconsistent Language-Code: line in some .po file of Plone 4.0.2

Antonio Carrasco Valero on gmail <[email protected]> Thu, 03 Mar 2011 10:31:46 +0100
Newsgroups gmane.comp.web.zope.plone.internationalization
Message-ID <[email protected]>
Some .po files with translations of Plone 4.0.2,
and quite likely other versions,
do not include in the .po header a line indicating the translations target
language
  -- something like "Language-Code: XX\n" , with XX replaced by a language
code

While the eggified structure of directories,
with a directory for each language,
serves nicely to Plone to associate the .po files with the intended
language,

the missing Language-Code: line in the .po
make difficult to deal with the translations out of the eggs folder
structure
(i.e. to incorporate all the translations in a translations program,
like my Plone translations application athttp://www.modeldd.org/).

I have attached the list of files with missing or wrong Language-Code: line.
Also attached a python script to cure most of the cases,
by replacing or inserting a "Language-Code:" line with a language code
derived from the directories structure.

But, if would be nice if contributors to Plone translations
could actually fix the .po files.

Cheers,
Antonio Carrasco Valero
Model Driven Development, sl
Valencia, Spain

-- 

Antonio Carrasco Valero
[email protected]

Model Driven Development, sl
Valencia España (Spain)
www.ModelDD.org

------------------------------------------------------------------------------
Free Software Download: Index, Search & Analyze Logs and other IT data in 
Real-Time with Splunk. Collect, index and harness all the fast moving IT data 
generated by your applications, servers and devices whether physical, virtual
or in the cloud. Deliver compliance at lower cost and gain new business 
insights. http://p.sf.net/sfu/splunk-dev2dev

_______________________________________________
Plone-i18n mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/plone-i18n
Plone402posWWrongLanguageCode.txt (text/plain, 15.8 KB)
buildout-cache\eggs\five.formlib-1.0.3-py2.6.egg\five\formlib\tests\locales\de\LC_MESSAGES\formtest.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\af\LC_MESSAGES\plonelocales.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\ar\LC_MESSAGES\plonelocales.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\bg\LC_MESSAGES\plonelocales.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\bn\LC_MESSAGES\plonelocales.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\ca\LC_MESSAGES\plonefrontpage.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\ca\LC_MESSAGES\plonelocales.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\cs\LC_MESSAGES\plonefrontpage.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\cs\LC_MESSAGES\plonelocales.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\cy\LC_MESSAGES\plonelocales.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\da\LC_MESSAGES\plonelocales.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\de\LC_MESSAGES\plonelocales.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\el\LC_MESSAGES\plonelocales.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\en\LC_MESSAGES\plonefrontpage.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\eo\LC_MESSAGES\plonefrontpage.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\eo\LC_MESSAGES\plonelocales.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\es\LC_MESSAGES\plonefrontpage.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\es\LC_MESSAGES\plonelocales.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\et\LC_MESSAGES\plonelocales.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\eu\LC_MESSAGES\plonefrontpage.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\eu\LC_MESSAGES\plonelocales.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\fa\LC_MESSAGES\plonelocales.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\fi\LC_MESSAGES\plonefrontpage.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\fi\LC_MESSAGES\plonelocales.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\fu\LC_MESSAGES\plonelocales.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\he\LC_MESSAGES\plonefrontpage.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\he\LC_MESSAGES\plonelocales.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\hi\LC_MESSAGES\plonelocales.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\hr\LC_MESSAGES\plonelocales.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\hu\LC_MESSAGES\plonelocales.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\hy\LC_MESSAGES\plonelocales.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\id\LC_MESSAGES\plonelocales.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\it\LC_MESSAGES\plonefrontpage.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\it\LC_MESSAGES\plonelocales.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\ja\LC_MESSAGES\plonefrontpage.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\ja\LC_MESSAGES\plonelocales.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\ka\LC_MESSAGES\plonelocales.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\kn\LC_MESSAGES\plonelocales.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\ko\LC_MESSAGES\plonelocales.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\lt\LC_MESSAGES\plonelocales.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\lv\LC_MESSAGES\plonelocales.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\mi\LC_MESSAGES\plonelocales.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\my\LC_MESSAGES\plonelocales.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\nl\LC_MESSAGES\plonefrontpage.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\nl\LC_MESSAGES\plonelocales.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\nn\LC_MESSAGES\plonelocales.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\no\LC_MESSAGES\plonefrontpage.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\no\LC_MESSAGES\plonelocales.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\pl\LC_MESSAGES\plonefrontpage.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\pl\LC_MESSAGES\plonelocales.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\pt\LC_MESSAGES\plonefrontpage.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\pt\LC_MESSAGES\plonelocales.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\pt_BR\LC_MESSAGES\atcontenttypes.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\pt_BR\LC_MESSAGES\atreferencebrowserwidget.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\pt_BR\LC_MESSAGES\cmfeditions.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\pt_BR\LC_MESSAGES\cmfplacefulworkflow.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\pt_BR\LC_MESSAGES\linguaplone.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\pt_BR\LC_MESSAGES\passwordresettool.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\pt_BR\LC_MESSAGES\plone.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\pt_BR\LC_MESSAGES\plonefrontpage.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\pt_BR\LC_MESSAGES\plonelocales.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\rm\LC_MESSAGES\plonelocales.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\ro\LC_MESSAGES\plonelocales.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\ru\LC_MESSAGES\plonelocales.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\sk\LC_MESSAGES\plonefrontpage.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\sk\LC_MESSAGES\plonelocales.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\sm\LC_MESSAGES\plonelocales.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\sq\LC_MESSAGES\plonelocales.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\sr\LC_MESSAGES\plonelocales.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\sr_Latn\LC_MESSAGES\atcontenttypes.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\sr_Latn\LC_MESSAGES\atreferencebrowserwidget.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\sr_Latn\LC_MESSAGES\cmfeditions.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\sr_Latn\LC_MESSAGES\cmfplacefulworkflow.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\sr_Latn\LC_MESSAGES\linguaplone.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\sr_Latn\LC_MESSAGES\passwordresettool.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\sr_Latn\LC_MESSAGES\plone.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\sr_Latn\LC_MESSAGES\plonelocales.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\sv\LC_MESSAGES\plonelocales.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\ta\LC_MESSAGES\plonelocales.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\te\LC_MESSAGES\plonelocales.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\to\LC_MESSAGES\plonelocales.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\tr\LC_MESSAGES\plonefrontpage.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\tr\LC_MESSAGES\plonelocales.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\uk\LC_MESSAGES\plonefrontpage.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\uk\LC_MESSAGES\plonelocales.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\vi\LC_MESSAGES\plonefrontpage.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\vi\LC_MESSAGES\plonelocales.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\zh_CN\LC_MESSAGES\atcontenttypes.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\zh_CN\LC_MESSAGES\atreferencebrowserwidget.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\zh_CN\LC_MESSAGES\cmfeditions.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\zh_CN\LC_MESSAGES\cmfplacefulworkflow.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\zh_CN\LC_MESSAGES\linguaplone.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\zh_CN\LC_MESSAGES\passwordresettool.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\zh_CN\LC_MESSAGES\plone.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\zh_CN\LC_MESSAGES\plonelocales.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\zh_HK\LC_MESSAGES\atcontenttypes.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\zh_HK\LC_MESSAGES\atreferencebrowserwidget.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\zh_HK\LC_MESSAGES\cmfeditions.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\zh_HK\LC_MESSAGES\cmfplacefulworkflow.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\zh_HK\LC_MESSAGES\linguaplone.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\zh_HK\LC_MESSAGES\passwordresettool.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\zh_HK\LC_MESSAGES\plone.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\zh_HK\LC_MESSAGES\plonelocales.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\zh_TW\LC_MESSAGES\atcontenttypes.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\zh_TW\LC_MESSAGES\atreferencebrowserwidget.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\zh_TW\LC_MESSAGES\cmfeditions.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\zh_TW\LC_MESSAGES\cmfplacefulworkflow.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\zh_TW\LC_MESSAGES\linguaplone.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\zh_TW\LC_MESSAGES\passwordresettool.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\zh_TW\LC_MESSAGES\plone.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\zh_TW\LC_MESSAGES\plonefrontpage.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales\zh_TW\LC_MESSAGES\plonelocales.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales-addons\ja\LC_MESSAGES\plone.app.caching.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales-addons\ja\LC_MESSAGES\plone.app.ldap.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales-addons\pt_BR\LC_MESSAGES\plone.app.caching.po
buildout-cache\eggs\plone.app.locales-4.0.3-py2.6.egg\plone\app\locales\locales-addons\pt_BR\LC_MESSAGES\plone.app.ldap.po
buildout-cache\eggs\products.tinymce-1.1.5-py2.6.egg\Products\TinyMCE\locales\fr\LC_MESSAGES\plone.tinymce.po
buildout-cache\eggs\products.tinymce-1.1.5-py2.6.egg\Products\TinyMCE\locales\ja\LC_MESSAGES\plone.tinymce.po
buildout-cache\eggs\products.tinymce-1.1.5-py2.6.egg\Products\TinyMCE\locales\pt_BR\LC_MESSAGES\plone.tinymce.po
buildout-cache\eggs\products.tinymce-1.1.5-py2.6.egg\Products\TinyMCE\locales\uk\LC_MESSAGES\plone.tinymce-manual.po
buildout-cache\eggs\products.tinymce-1.1.5-py2.6.egg\Products\TinyMCE\locales\uk\LC_MESSAGES\plone.tinymce.po
buildout-cache\eggs\products.tinymce-1.1.5-py2.6.egg\Products\TinyMCE\locales\zh_TW\LC_MESSAGES\plone.tinymce.po
buildout-cache\eggs\products.tinymce-1.1.5-py2.6.egg\Products\TinyMCE\locales\zh_TW\LC_MESSAGES\tinymce.po
buildout-cache\eggs\zope.app.form-3.8.1-py2.6.egg\zope\app\form\browser\tests\locales\de\LC_MESSAGES\formtest.po
buildout-cache\eggs\zope.app.locales-3.6.2-py2.6.egg\zope\app\locales\de\LC_MESSAGES\zope.po
buildout-cache\eggs\zope.app.locales-3.6.2-py2.6.egg\zope\app\locales\en\LC_MESSAGES\zope.po
buildout-cache\eggs\zope.app.locales-3.6.2-py2.6.egg\zope\app\locales\es\LC_MESSAGES\zope.po
buildout-cache\eggs\zope.app.locales-3.6.2-py2.6.egg\zope\app\locales\fr\LC_MESSAGES\zope.po
buildout-cache\eggs\zope.app.locales-3.6.2-py2.6.egg\zope\app\locales\he\LC_MESSAGES\zope.po
buildout-cache\eggs\zope.app.locales-3.6.2-py2.6.egg\zope\app\locales\hu\LC_MESSAGES\zope.po
buildout-cache\eggs\zope.app.locales-3.6.2-py2.6.egg\zope\app\locales\it\LC_MESSAGES\zope.po
buildout-cache\eggs\zope.app.locales-3.6.2-py2.6.egg\zope\app\locales\ja\LC_MESSAGES\zope.po
buildout-cache\eggs\zope.app.locales-3.6.2-py2.6.egg\zope\app\locales\nl\LC_MESSAGES\zope.po
buildout-cache\eggs\zope.app.locales-3.6.2-py2.6.egg\zope\app\locales\pl\LC_MESSAGES\zope.po
buildout-cache\eggs\zope.app.locales-3.6.2-py2.6.egg\zope\app\locales\pt_BR\LC_MESSAGES\zope.po
buildout-cache\eggs\zope.app.locales-3.6.2-py2.6.egg\zope\app\locales\ru\LC_MESSAGES\zope.po
buildout-cache\eggs\zope.app.locales-3.6.2-py2.6.egg\zope\app\locales\tr\LC_MESSAGES\zope.po
buildout-cache\eggs\zope.app.locales-3.6.2-py2.6.egg\zope\app\locales\zh_CN\LC_MESSAGES\zope.po
buildout-cache\eggs\zope.app.locales-3.6.2-py2.6.egg\zope\app\locales\zh_TW\LC_MESSAGES\zope.po
buildout-cache\eggs\zope.i18n-3.7.4-py2.6.egg\zope\i18n\tests\locale\de\LC_MESSAGES\zope-i18n.po
buildout-cache\eggs\zope.i18n-3.7.4-py2.6.egg\zope\i18n\tests\locale\en\LC_MESSAGES\zope-i18n.po
buildout-cache\eggs\zope.i18n-3.7.4-py2.6.egg\zope\i18n\tests\locale2\en\LC_MESSAGES\zope-i18n.po
buildout-cache\eggs\zope.i18n-3.7.4-py2.6.egg\zope\i18n\tests\locale3\en\LC_MESSAGES\zope-i18n.po
buildout-cache\eggs\zope.i18n-3.7.4-py2.6.egg\zope\i18n\tests\locale3\en\LC_MESSAGES\zope-i18n2.po
buildout-cache\eggs\zope2-2.12.13-py2.6-win32.egg\Products\Five\tests\locales\de\LC_MESSAGES\fivetest.po
buildout-cache\eggs\zope2-2.12.13-py2.6-win32.egg\Products\Five\tests\locales\en\LC_MESSAGES\fivetest.po
MDDfixPlone4pos.py (text/plain, 10.8 KB)
# -*- coding: utf-8 -*-
#
# File: MDDfixPlone4pos.py
#
# Copyright (c) 2011  by Model Driven Development sl and Antonio Carrasco Valero
#
# GNU General Public License (GPL)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
#
# Authors: 
# Model Driven Development sl  Valencia (Spain) www.ModelDD.org 
# Antonio Carrasco Valero                       [email protected]
#

__author__ = """Model Driven Development sl <[email protected]>,
Antonio Carrasco Valero <[email protected]>"""
__docformat__ = 'plaintext'


import sys


import os


cUsage_Msg = 'Given a parameter with the path for a source folder, and a path for an EMPTY target folder, scans the source folder for GNU gettext .PO files, extracting language codes from the name of container folders of LC_MESSAGES.'
cParms_Msg = 'Please, supply as arguments a path for a source folder, and a path for a target folder'

cError_SourcePathDoesNotExist_Msg = 'Source path does not exist'
cError_TargetPathDoesNotExist_Msg = 'Target path does not exist'

cError_SourceFileReadError_Msg    = 'Source file read error'
cError_TargetFileWriteError_Msg   = 'Target file write error'


cFilePostfix_po  = '.po'
cFilePostfix_pot = '.pot'


cFileOpenReadMode       = 'rb'
cFileOpenReadBuffering  = 0
cFileOpenWriteMode      = 'wb'
cFileOpenWriteBuffering = 0

cLanguageCodePOEntry        = '"Language-Code:'
cLanguageCodePOEntry_lower  = cLanguageCodePOEntry.lower()

cLanguageCodePOEntry_LinePattern = '"Language-Code: %s\\n"'


cFolderName_LC_MESSAGES  = 'LC_MESSAGES'


cSampleSourcePath = 'D:\dvpt\Plone402\buildout-cache\eggs'
cSampleTargetPath = 'D:\Works\MDD\Plone\gvSIGi18n\DatosImportacion_gvSIGi18n\From_Plone402\All'


def main():
    """Given a parameter with the path for a source folder, and a path for a target folder, scans the source folder for GNU gettext .PO files, extracting language codes from the name of container folders of LC_MESSAGES.
    
    """
    
    
    aSourcePath = ''
    aTargetPath = ''
    
    someArguments = sys.argv
    if not ( someArguments and len( someArguments) > 2):
        print( cUsage_Msg)
        print( cParms_Msg)
        sys.exit(2)

    aSourcePath = someArguments[ 1]
    aTargetPath = someArguments[ 2]
    
    if ( not aSourcePath) or ( not aTargetPath):
        print( cUsage_Msg)
        print( cParms_Msg)
        sys.exit(2)
        
    aSourcePathExists = False
    try:
        aSourcePathExists = os.path.exists( aSourcePath)
    except:
        None
    if not aSourcePathExists:
        print( cUsage_Msg)
        print( '%s\n%s' % ( cError_SourcePathDoesNotExist_Msg, aSourcePath,))
        
    aTargetPathExists = False
    try:
        aTargetPathExists = os.path.exists( aTargetPath)
    except:
        None
    if not aTargetPathExists:
        print( cUsage_Msg)
        print( '%s\n%s' % ( cError_SourcePathDoesNotExist_Msg, aTargetPath,))
        

        
        
        
    for unRoot, unosDirectories, unosFileNames in os.walk( aSourcePath):
        
        for unFileName in unosFileNames:

            unAddedLanguageCode = False
            
            unFileNameAction = 'Nothing'
            aTargetFileName  = ''
            
            unIsPO  = unFileName.lower().endswith( cFilePostfix_po)
            unIsPOT = unFileName.lower().endswith( cFilePostfix_pot)
            
            if unIsPO or unIsPOT:
                
                unFilePath = os.path.join( unRoot, unFileName)
                
                if not os.path.exists( unFilePath):
                    
                    unFileNameAction = 'DoesNotExists'
                    
                else:
                        
                    aSourceRead = False
                    aSourceText = ''
                    try:
                        aSourceFile = None
                        try:
                            aSourceFile = open( unFilePath, cFileOpenReadMode, cFileOpenReadBuffering)
                            if not ( aSourceFile == None):
                                aSourceText = aSourceFile.read()
                        finally:
                            if aSourceFile:
                                aSourceFile.close()
                        aSourceRead = True
                        
                    except IOError:
                        unFileNameAction = 'ReadError'
                        print( '%s\n%s' % ( cError_SourceFileReadError_Msg, unFilePath,))

                    unFileNameAction = 'Read'
                        
                        
                    if aSourceRead:
                        
                        
                        aTargetFileName = unFileName
                        aTargetFileNameHead, aTargetFileNameExt = os.path.splitext( aTargetFileName)
                        
                        aTargetFilePath = os.path.join( aTargetPath, aTargetFileName)
                        
                        if os.path.exists( aTargetFilePath):
                            
                            unFileNameAction = '%s %s' % ( unFileNameAction , 'DuplicateTarget',)
                            
                            aTargetFileNameCounter = 1
                            while True:
                                aTargetFileName = '%s-%d%s' % ( aTargetFileNameHead, aTargetFileNameCounter, aTargetFileNameExt,)
                                aTargetFilePath = os.path.join( aTargetPath, aTargetFileName)
                                
                                if not os.path.exists( aTargetFilePath):
                                    break
                                aTargetFileNameCounter += 1
                                
                                
                        unSourceLinesChanged = False       
                        unLanguageCodeLineIndex = -1
                        unLanguageCodeInLine = ''
                        
                        someSourceLines = aSourceText.splitlines()    
                        for aLineIndex in range( len( someSourceLines)):
                            aSourceLine = someSourceLines[ aLineIndex]
                            
                            if aSourceLine.lower().startswith( cLanguageCodePOEntry_lower):
                                
                                unLanguageCodeLineIndex = aLineIndex
                                
                                unCode = aSourceLine[ len( cLanguageCodePOEntry_lower):].replace( '\\n', '')
                                unCode = unCode.strip()
                                unQuoteIndex = unCode.find( '"', 0)  
                                if unQuoteIndex >= 0:   
                                    unLanguageCodeInLine = unCode[ :unQuoteIndex]
                                    if unCode:
                                        unHasLanguageCodeLine = True
                                        
                                break
                            

                        unLanguageCodeFromPath = ''
                        unLC_MESSAGESPosition = unFilePath.find(  cFolderName_LC_MESSAGES)
                        if unLC_MESSAGESPosition > 0:


                            unPathSeparator = unFilePath[ unLC_MESSAGESPosition - 1]
                            unCharIndex = unLC_MESSAGESPosition - 2
                                    
                            while unCharIndex:
                                unChar = unFilePath[ unCharIndex]
                                if unChar == unPathSeparator:
                                    break
                                unLanguageCodeFromPath = '%s%s' % ( unChar, unLanguageCodeFromPath, )
                                unCharIndex -= 1
                            
                                
                        if unLanguageCodeFromPath:
                            if ( not unLanguageCodeInLine) or not ( unLanguageCodeInLine == unLanguageCodeFromPath):
                            
                                aNewLine = cLanguageCodePOEntry_LinePattern % unLanguageCodeFromPath
                                
                                if unLanguageCodeLineIndex >= 0:
                                    someSourceLines[ unLanguageCodeLineIndex] = aNewLine
                                    unFileNameAction = '%s %s' % ( unFileNameAction , 'REPLACED-LanguageCodeLine',)
                                else:
                                    someSourceLines.insert( 0, aNewLine)
                                    unFileNameAction = '%s %s' % ( unFileNameAction , 'ADDED-LanguageCodeLine',)
                                    
                                unSourceLinesChanged = True
                            
                                    
                         
                                    
                        if unSourceLinesChanged:
                            unTargetText = '\n'.join( someSourceLines)
                        else:
                            unTargetText = aSourceText
                            

                        aWritten = False
                        try:
                            aTargetFile  = None
                            try:
                                aTargetFile = open( aTargetFilePath, cFileOpenWriteMode, cFileOpenWriteBuffering)
                                aTargetFile.write( unTargetText)
                            finally:
                                if aTargetFile:
                                    aTargetFile.close()
                            aWritten = True
                        except IOError:
                            print( '%s\n%s' % ( cError_TargetFileWriteError_Msg, aTargetFilePath,))
 
                        if aWritten:
                            unFileNameAction = '%s %s' % ( unFileNameAction , 'Written',)
                        else:
                            unFileNameAction = '%s %s' % ( unFileNameAction , 'WRITE FAILED',)
        
                if unSourceLinesChanged:
                    print( unFilePath)
                
                # print( '%s %s %s' % ( unFilePath, aTargetFileName, unFileNameAction,))
            
    sys.exit( 0)
    
    
if __name__ == '__main__':
    main()