Code Styling Project

It’s not a bug, it’s always a feature.
  • Deutsch
  • English
  • rss
  • Home
  • Blog
  • Imprint
  • Development
  • Manuals
  • Bugfixing

Codestyling Localization and PoEdit are compatible now

codestyling | 17. August 2010 | 21:52

Since few month often problems occured with the translation files (*.po) my plugin war creating. PoEdit was able to load them but failed to save the language file after translation and shows up a lot of error messages. Futhermore my plugin was able to create non standard language files (*.mo) this way.

I found the issue finally and wrote again a bugfix at my plugin. With version 1.99.1 this was solved and meets the way PoEdit expect it.

First of all I present a short list of web pages which were discussing this topic more or less expensive and also did come up with temporary solution how to patch the *.po files my plugin did create:

  • Dennis Morhardt (www.dennismorhardt.de)
  • WordPress Deutschland Forum
  • Freelance Jobs

For a better understanding why and where this problem occured, I will give you a short briefly description about this phenomenon. And we need at least some code examples to visualize it. I took one from WordPress 3.0.1 version and did create my own artificial one too.

existing real life example

As mentioned above this is the real life example out of the WordPress 3.0.1 core PHP code.

PHP
1
2
3
4
5
6
7
8
9
10
11
12
//file: wp-admin/includes/dashboard.php:264
// Categories
 $num = number_format_i18n( $num_cats );
 $text = _n( 'Category', 'Categories', $num_cats );
 
//file: wp-includes/taxonomy.php:55
'labels' => array(
     'name' => __( 'Categories' ),
     'singular_name' => __( 'Category' ),
     'update_item' => __( 'Update Category' ),
),
 
timing: 0.366s

The term “Category” has been used as pluralization and also as singular term. Normally those occurances are different for translation because they are always bound to the context where the have been used. My plugins consequently threat them as 2 different entries. But this forces PoEdit to utilize 2 times the same msgid in this case. But it is not permitted to have duplicate entries at localization files. So PoEdit was not able to generated the language file (*.mo) and stopped the generation process with a lot of warnings.

artificial self created example

For testing purpose I did create an artificial example. I will use it to explain that the pure bugfix by it’s own is not the full story. Programer should also know at every time, what they are doing and should also spend some time understanding how localization works, if they code it into their software.

PHP
1
2
3
4
5
6
7
<div>Testing container: 
 <?php _e('All'); ?> 
vs.
 <?php echo _n('All', 'All', $count); ?> 
vs. 
 <?php echo _n('All', 'Total', $count); ?>
</div>
timing: 0.100s

Again the same problem: singular and plural term are sharing the same main key “All” at sources. But additionally there is also a second plural term with equal main key but tries to explain somethings completely different at the whole thing.

But what will happen, if PoEdit will reads the terms out ouf the source files by it’s own ?
It’s easy to show and will look like this result at your *.po file:

GNU Gettext
1
2
3
4
5
6
7
#: index.php:11
#: index.php:13
#: index.php:15
msgid "All"
msgid_plural "Total"
msgstr[0] ""
msgstr[1] ""
timing: 0.001s

Surprise, suprise, isn’t it? At the end only one can survive this battle. As you can see the plural terms All -> All are gone completely and the information, that there was also a singular term is not longer visible and known. If you now translate this file you will wonder later on, why some places at the UI won’t show you the expected results or funny texts.

One essential thing has been left out completely during localization: All texts anywhere visible at the UI are always related to the surrounding place they oocur or the other text arround it. That’s why those things can be handled with context specific localization functions provided by the gettext interface or you modify the terms to avoid any of this collisions. But this is a much bigger story and would blow up this article.

Plugin Bugfix and advantages for programers/translators

It was essential for me to get informed about those potential problems. That’s why my plugin has been extended to remark those cases at the coding comment entries of *.po files. Doing so not only my plugins will show them but also PoEdit will show this comments as well. Having such a case in doubt, somebody can inspect it and make the right decisions for solving this issues.

At my plugin it will look like this one taken from my example above:

conclusion

My new version 1.99.1 is about to be published soon. It will now create again the well formed *.po files compatible to what PoEdit expects and supports. They also can be exported into correct language files by both of them.
As you can see out of the examples I have shown, localization is no “kindergarden” work. You will need at least basic knowledge about languages and their utilization/behavior. Only with this knowledge you will be able to develop clear forwarded translatable modules.

As developer of Themes or Plugins it will be a good idea to deal with backgrounds of translation work too, if you have the wish to publish really good and programatic translatable software.

Categories
English, WordPress (US)
Comments rss
Comments rss

« Codestyling Localization supports now BuddyPress and bbPress WPTouch iPhone Theme and the crippled translation »

4 responses    Leave a comment

Master Po

Master Po

28.08.2010 | 15:05

Hi, I installed your plugin in order to personalize some strings in the italian official localization of buddypress, but I got a “warning” in the wordpress administration… can you please explain me?
here the warning:

PHP
1
Warning: preg_match() [function.preg-match]: Unknown modifier 'b' in /home/masterpo/public_html/wp-content/plugins/codestyling-localization/codestyling-localization.php on line 595
timing: 0.168s

thank you so much!
ciao :)
Master Po

reply »

codestyling

codestyling

28.08.2010 | 17:40

Could you please list the Themes (and best case the download locations) you having in use at the Themes folder? Because it looks like a Theme is causing this issue and I would need the theme forcing this to check the reason. There seems something invalid at the themes header informations, so i would need it for reproducing locally.
You did nothing wrong, there is something wrong in the Theme I didn’t expect at my code. So prior to fix this in my coode, I have to reproduce it.

reply »

codestyling

codestyling

29.08.2010 | 22:24

second notice: please use the updated version 1.99.3 to solve this issue. This occures while your theme is located at a deeper folder hierarchy as expected.
Example: /wp-content/themes/my-buddypress-themes/bp-default/

reply »

ahmet

ahmet

09.11.2011 | 00:17

How to translate plural items? I only see index result=0 so I can only edit the singular form. Where do I change this formula?

reply »

You can use these tags : <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Navigation

  • Common
  • jQuery at WordPress
  • WordPress (US)

Search

Newer Posts ...

  • Scripting Guard - a WordPress Plugin protects itself
  • WP e-Commerce breaks intentionally other Plugins or Themes
  • IDN Sites, WordPress Admin and JSON problems
  • Plugin WP System Health is now translatable and polished
  • WPTouch iPhone Theme and the crippled translation

Older Posts ...

  • Codestyling Localization supports now BuddyPress and bbPress
  • jQuery 1.3.2 causes problems at IE 8
  • “Page Columnist” - Posts and Pages at Column Layout
  • WordPress 2.8 changes the metabox model for admin pages
  • How to use Wordpress Metaboxes at own plugins
rss Comments rss valid xhtml 1.0 design by jide powered by Wordpress get firefox