Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2005-05-29 01:50:12

Mary
Sock Enthusiast
Registered: 2004-06-27
Posts: 6,236

Enabling Plugin Translation

The “why” should be obvious, the how and when, etc, is what I’m asking.

Its fine, of course, if you’re english-speaking, since most plugins are in english. And sometimes the word you want is already in the lang files, so no problem.

Making plugins is fun, the idea being that someone can use it for something. I’d (and I’d assume others would) like to make things easier on whomever is doing the translating, so they don’t have to look through every line of the plugin, making edits to the plugin itself, having to do this every time the plugin gets updated.

Ideas? View points? Something glaringly obvious I’m missing?

Offline

#2 2005-05-29 11:49:53

tranquillo
Archived Plugin Author
Registered: 2005-03-07
Posts: 127
Website

Re: Enabling Plugin Translation

I try to put gTxt() funtionality in my plugin code. <a href=“http://forum.textpattern.com/viewtopic.php?pid=55905#p55905”>Here’s</a> my suggestion for the plugin template.
I don’t know, if this is possible for the help text in plugins, too.

Offline

#3 2005-05-29 12:28:52

Sencer
Archived Developer
From: cgn, de
Registered: 2004-03-23
Posts: 1,803
Website

Re: Enabling Plugin Translation

The problem then is, where do we put the language definitions? The language files are not a good idea, because this will lead to problems when updating textpattern. Also: The language for plugin is very local to the plugin, there is no benefit in making it available globally. Yet another argument against it is that the language system is due for a little overhaul like Seperating front-end and back-end language stuff.

Another idea is, using two files: one for the plugin-code and one for the language-definitions, but IMHO this would be more of a hassle than a help.

One way to improve the current situation, while still not being optimal, would be if plugin authors started making the distinction between code and language themselves. So for example you would start your plugin with:

<notextile><pre>
function abc_something {
$my_textarray = array(
‘abc_title’ => ‘My great Plugin’
‘abc_something’ => ‘here is another text’
);

//Here the actual code starts
echo $my_textarray[‘abc_title’];
</pre></notextile>

Now if people make the uncompiled plugin template available, other people can translate it and offer it. Or, if you install some random plugin, you can at least easily change the language stuff easily without reading through the whole code.

Last edited by Sencer (2005-05-29 12:42:15)

Offline

#4 2005-05-29 13:25:10

marios
Archived Plugin Author
Registered: 2005-03-12
Posts: 1,253

Re: Enabling Plugin Translation

When thinking about I18N it would make sense then to store the language terms in an array,but instead of having them left in the language files they should be stored in extra data base tables, and then there should be an option somewhere in the admin interface that fetches them and apdates the extra language tables in the database, so the language terms can expand dynamically.

regrds,marios

Last edited by marios (2005-05-29 13:25:45)


⌃ ⇧ < ⌃ ⇧ >

Offline

#5 2005-05-29 13:26:08

Etz Haim
Archived Plugin Author
From: Karlstad, Sweden
Registered: 2005-01-24
Posts: 262
Website

Re: Enabling Plugin Translation

gTxt() is a good idea as long as the user is not required to change his language file. For my 2 lepta-worth, I code a default english message in my plugins, and allow an optional argument to change it.

Offline

#6 2005-05-29 15:19:51

Andrew
Plugin Author
Registered: 2004-02-23
Posts: 730

Re: Enabling Plugin Translation

The issue of internationalization occurred to me while making the Workflow plugin, because of the auto-generated email. I couldn’t come up with a solution right off the bat, but I’m very interested in reaching a clever solution to this.

Offline

#7 2005-05-30 08:37:46

tranquillo
Archived Plugin Author
Registered: 2005-03-07
Posts: 127
Website

Re: Enabling Plugin Translation

I prefer a separate plugin language file (in this example in the textpattern/lang/plugins folder; filename: pluginname_en-gb.txt). By adding the following code to the plugins, you can grab the translations out of it:

<code>
if (@txpinterface == ‘admin’) {

global $textarray; $pluginname = “zem_admin_test”; $out = load_plugin_lang(LANG, $pluginname); $textarray = array_merge ($textarray, $out); $tab_title = gTxt(‘tab_testing’); // Add a new tab under ‘extensions’ called ‘testing’, for the ‘test’ event register_tab(“extensions”, “test”, $tab_title);

// ‘zem_admin_test’ will be called to handle the ‘test’ event register_callback($pluginname, “test”); }

function zem_admin_test($event, $step) {

// ps() returns the contents of POST vars, if any $something = ps(“something”); pagetop(“Testing”, (ps(“do_something”) ? “you typed: $something” : “”));

// The eInput/sInput part of the form is important, setting the event and step respectively

echo “<div align=\“center\” style=\“margin-top:3em\”>”; echo form( tag(“Test Form”, “h3”). graf(gTxt(‘tab_test’).”: “. fInput(“text”, “something”, $something, “edit”, “”, “”, “20”, “1”). fInput(“submit”, “do_something”, “Go”, “smallerbox”). eInput(“test”).sInput(“step_a”) ,” style=\“text-align:center\”“) ); echo “</div>”; }

function load_plugin_lang($lang, $pluginname) { global $txpcfg; $filename = is_file($txpcfg[‘txpath’].’/lang/plugins/’.$pluginname.’_’.$lang.’.txt’) ? $txpcfg[‘txpath’].’/lang/plugins/’.$pluginname.’_’.$lang.’.txt’ : ‘’;

$file = fopen($filename, "r"); if ($file) { while (!feof($file)) { $line = fgets($file, 4096); if($line[0]=='#') continue; list($name,$val) = explode(’ => ‘,trim($line)); $out[$name] = $val; } @fclose($filename); } return ($out) ? $out : ‘’; }</code>

What do you think?

Last edited by tranquillo (2005-05-30 08:40:29)

Offline

#8 2005-05-30 14:07:43

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: Enabling Plugin Translation

What would be very nice too is the ability to have a parallel use of one plugin in more than one language.
My example: I use zem_contact on a multilingual site. What I would like to be able to do is output the error messages (that are hardcoded) on every page in it’s own language. So beside the output in english I would need two other languages.
I suppose this is not exactly what you were talking about, but if you are thinking about plugin translation, you might be willing to think just this little bit further…?

Offline

#9 2005-06-01 11:49:39

obeewan
Archived Plugin Author
From: Stockholm, Sweden
Registered: 2004-08-12
Posts: 319
Website

Re: Enabling Plugin Translation

There is ofcourse the way of adding attributes to the plugin tag for all the text that it uses (I’ve done this on my ob1-googlenav) but with more sofisticated plugins this might be hard and create more and more tagsoup.


Plugins: ob1_advanced_search 1.032b, ob1_search_score 1.0, ob1_pagination 2.5, ob1_title 4.1, ob1_modified 2.1

“Let your plans be dark and as impenetratable as night, and when you move, fall like a thunderbolt.”
— Sun Tzu

Offline

Board footer

Powered by FluxBB