Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#1 2011-02-01 17:35:31
- ~cXc~
- Plugin Author
- Registered: 2010-12-27
- Posts: 39
How do you use textpacks in plugins?
I’m trying to figure out how to use textpacks so my plugins can be translated but I can’t figure out what all is required to get it to work and have gotten all kinds of errors trying to figure it out … I’m no where near the coder most of you are
I’ve looked for plugins that use them but they are few to use for reference, any advice snippets or reference material would be greatly appreciated.
http://textbook.textpattern.net/wiki/index.php?title=Textpacks could use a quick little example also …
~cXc~
Last edited by ~cXc~ (2011-02-01 17:50:15)
Offline
Re: How do you use textpacks in plugins?
Here’s my one example of a plugin with a Textpack (as of today I’d recommend looking at the version in the dev
branch). This has the strings coded into the plugin file itself, which is OK for a small Textpack. Bloke’s working on something more general purpose with the plugin composer he maintains.
Code is topiary
Offline
Re: How do you use textpacks in plugins?
You already have noticed the plugin example, I assume?
Offline
#4 2011-02-01 19:09:41
- ~cXc~
- Plugin Author
- Registered: 2010-12-27
- Posts: 39
Re: How do you use textpacks in plugins?
guess I’ll just wait for the plugin composer update until then I’ll just use this …
/*
PLUGIN CODE::LANGUAGE SUPPORT = cxc_templates_gTxt('')
-------------------------------------------------------------
*/
function cxc_templates_gTxt($what, $atts = array()) {
$lang = array(
'cxc_tpl_templates_tab' => 'Templates',
);
return strtr($lang[$what], $atts);
}
Its the only language support I was able to understand
Plus, I’m not sure how to go about getting the textpack info into my header meta area of the plugin anyway o.O so I guess just getting it all ready for the new feature will work :) thanks for sending me to your source code Jeff, I installed and exported your plugin to php with ied_plugin_composer but the additional header info was not there, even with it though I still don’t understand and couldn’t get it working.
Robert, I hadn’t seen the example plugin but even with it I was unable to figure out how to get it working I added the …
$plugin['textpack'] = <<< EOT
#@public
#@language en-gb
cxc_tpl_templates_tab => Templates
#@test
#@language en-gb
cxc_tpl_templates_tab => Templates
EOT;
… but it only displays cxc_tpl_templates_tab instead of Templates that has been the problem the whole time TBH I must be missing something
Offline
Re: How do you use textpacks in plugins?
The Composer (v1.00 dev version, not yet publicly available) now has the ability to keep track of gTxt()
strings that you use in your code. When you write the translation strings in as you code, they are written to your database so you can test your plugin immediately on your local installation. It automatically adds textpack strings that all begin with your nominated plugin prefix and you can remove any that you’re no longer using.
The final hurdle is for me to code the bit that collects the strings together in your nominated export language(s) and packages them into the plugin header for you when you publish the plugin. Not a huge job.
There’ll also be a facility for exporting packs in any language(s) so they can be linked from the new textpattern.org site alongside the plugin itself. I’m just sidetracked slightly with smd_tags right now for a project but I’ll get right back onto the Composer after that. Shouldn’t be long before I can release a beta. And it has a new look too with a tasty extra feature for coders (like me) who hate to wait.
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
#6 2011-02-01 19:34:35
- ~cXc~
- Plugin Author
- Registered: 2010-12-27
- Posts: 39
Re: How do you use textpacks in plugins?
Since I have to have the plugin composer in order to accomplish this should I continue with the translations the way I am above or just wait for the new version Stef?
I’ve wasted a lot of time trying to understand this already I just don’t want to waste anymore
Offline
Re: How do you use textpacks in plugins?
cXc wrote:
Since I have to have the plugin composer in order to accomplish this should I continue with the translations the way I am above or just wait for the new version Stef?
Well, you can do it manually by writing stuff into the template format and executing the template on the PHP command line. The composer is just a prettier interface for it and it (hopefully) integrates better into your workflow so it keeps your strings in sync with your code as automatically as it can. I’m probably a few days away from a beta drop. If you can wait that long then that’s cool.
Alternatively, if you’d like a copy of the current alpha composer (which does NOT export the strings yet, but allows you to create the textpack strings as you develop) then drop me a line.
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
#8 2011-02-01 20:03:43
- ~cXc~
- Plugin Author
- Registered: 2010-12-27
- Posts: 39
Re: How do you use textpacks in plugins?
The way I am doing it right now, the text on the tab (e.g. Templates) is translated but in all the examples I’ve looked at that seems to be what is used to determine when the gTxt(‘string’) is applied.
$plugin['textpack'] = <<< EOT
#@public
#@language en-gb
cxc_tpl_templates_tab => Templates
#@test
#@language en-gb
cxc_tpl_templates_tab => Templates
EOT;
In the example above where it says #@public or #@test what is that referring to?
I know normally # would denote a comment but unless I am misunderstanding everything in the example it is actually giving instructions on when the gTxt() is available and which textpack is being extended by the plugin.
Last edited by ~cXc~ (2011-02-01 20:50:25)
Offline