extend layout operators

I have 2 new requirements for my addon and am wondering which is the best way to do this.
I would like to extend the functionality of:
layout label
– so it will have the same auto language translate capabilities of a layout operator
and
layout operator
– so that the text can be left justified rather than the default center justified situation

I have had a look at the cookbook stuff.
Would this be the best solution or do something in the C code, or use a mixin to extend the class (I’m not sure this would even work as it’s pretty much mixing C code and a Python class one AFAIK -could be wrong often am- )

Any ideas/input would be helpful
Thanks

There is no real auto-translate, it rather happens accidentally if your label is identical to a translated string and also the context it is in needs to match. It can be explicitly disabled by layout.label(…, translate=False), it is True by default:

http://www.blender.org/documentation/blender_python_api_2_72_0/bpy.types.UILayout.html?highlight=label#bpy.types.UILayout.label

Right alignment: doesn’t work well as far as I remember, because it’s not really used in Blender and a visual no no anyway.

http://www.blender.org/documentation/blender_python_api_2_71_release/bpy.types.UILayout.html?highlight=uilayout#bpy.types.UILayout.alignment

Thanks CoDEmanX
I wanted left alignment in a button like it is in the label so all I am trying to do is make a button act like a label currently does.
Also, sorry I missed the bit in the docs Translate=True
The context bit then is what I need to work out.
I am using strings directly from the code ie tooltips or descriptions so there should be translations available. Maybe I need to duplicate the pattern match process to grep out the individual chunks from the translation files. What I am finding is individual words like Tooltip will auto work but a tooltip phrase doesn’t seem to.
I just thought that maybe if I separate them into single line phrases (currently I am using textwrap to make them fit visually) it might work.
I will try it and edit this post accordingly.
–update–
Nope that didn’t work. (I was going to use German as an example however the word Tooltip is not translated in the German version it works in Spanish so I used that instead)
Here’s the menu version



Here’s the label version in Spanish


and English


It is a one line label. I guess I have to do it manually.
The word Tooltip is translated but not the phrase.
Tooltip: won’t work however.
Also Tooltip will work even if there are other phrases on the same line.
Manually would probably be best so that I can still use textwrap to make the lines fit the box.

If you know where in the C or python the language search algorithm is that would help me greatly. If not I will track it down.

AFAIK there is no algorithm or anything, the widely used .po translation system is used (actually called gettext if I’m not mistaken):

There are utility functions to enable translations, such as IFACE_(…), in the C code:
http://wiki.blender.org/index.php/Dev:Source/Interface/Internationalization

Thanks that’s exactly the answer I needed

Ok the language part is done, the code below now works on most things.

Now all I need is to left justify the text in a button.
Anyone? Any ideas?

It’s a little out of context but you should be able to get the general idea.


def translate(text):
    txt = bpy.app.translations.pgettext_tip(text)
    if txt != text:
        return txt
    return text

translate(idtype.bl_rna.properties[prop].description)
translate(idtype.__doc__)