Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2010-03-03 11:30:22

wet
Developer
From: Lenzing, Austria
Registered: 2005-06-06
Posts: 3,267
Website

Textpacks: I18N facility for plugins and other third party software

Change set r3322 introduces Textpacks, an attempt to address the current lack of built-in i18n facilities for third-party extensions (plugins, themes) in Textpattern’s core.

In plain language, Textpacks are simple texts defining translations:

  • Textpacks have to adhere to a syntax along the lines of one used for the current language files.
  • They can either be added programmatic by calling install_textpack() or from the admin-side Preferences > Language tab.
  • They can contain more than one language set.

By adding a Textpack, its content becomes available to gTxt() and takes part in Textpattern’s i18n features just like any other string from the language server.

To avoid name clashes, we encourage Textpack authors to employ the usual three-letter-prefix disambiguation method for their string names.

A sample Textpack:

#@public
#@language en-gb
foo_checkbox => Checkbox
foo_contact => Contact
foo_email => Email
foo_email_subject => $var1 > Inquiry
foo_email_thanks => Thank you, your message has been sent.
# comment line
#@language de-de
foo_checkbox => Auswahl
foo_contact => Kontakt
foo_email => E-Mail
foo_email_subject => $var1 > Anfrage
foo_email_thanks => Vielen Dank. Ihre Nachricht wurde versandt.

Offline

#2 2010-03-03 12:23:13

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 3,435
Website

Re: Textpacks: I18N facility for plugins and other third party software

Ah, I saw the update on the feed last night and wondered what that was for. Sounds like a very good idea.


TXP Builders – finely-crafted code, design and txp

Offline

#3 2010-03-03 14:57:46

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

Re: Textpacks: I18N facility for plugins and other third party software

I love you.

;D

Offline

#4 2010-03-03 16:52:00

thebombsite
Plugin Author
From: Exmouth, England
Registered: 2004-08-24
Posts: 3,251
Website

Re: Textpacks: I18N facility for plugins and other third party software

Nice one. I wondered what it was myself at first though looking at the code I thought it was connected to language.


Stuart – The BombsiteProText ThemesTextgarden

In a Time of Universal Deceit
Telling the Truth is Revolutionary.

Offline

#5 2010-03-03 17:59:18

Els
Admin
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: Textpacks: I18N facility for plugins and other third party software

Very nice, thank you! But does this affect MLP?

Offline

#6 2010-03-03 19:11:01

Gocom
Plugin Author
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,530
Website

Re: Textpacks: I18N facility for plugins and other third party software

I love Wet. Have my babies?

Els wrote:

does this affect MLP?

No. The new functionality is used to insert language strings into DB.

Altho, it can be used with MLP to add new strings or distribute language packs.

Last edited by Gocom (2010-03-03 19:11:35)

Offline

#7 2010-03-03 19:51:02

candyman
Member
From: Italy
Registered: 2006-08-08
Posts: 684

Re: Textpacks: I18N facility for plugins and other third party software

Great news.

Offline

#8 2010-03-03 21:07:42

MattD
Plugin Author
From: Monterey, California
Registered: 2008-03-21
Posts: 1,251
Website

Re: Textpacks: I18N facility for plugins and other third party software

So is there a way plugin developers should/could use this to internationalize their plugins?


My Plugins

Piwik Dashboard, Google Analytics Dashboard, Minibar, Article Image Colorpicker, Admin Datepicker, Admin Google Map, Admin Colorpicker

Offline

#9 2010-03-03 21:50:17

Gocom
Plugin Author
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,530
Website

Re: Textpacks: I18N facility for plugins and other third party software

MattD wrote:

So is there a way plugin developers should/could use this to internationalize their plugins?

As wet stated in OP, yes.

Plugin authors can install language strings from a plugin with something like:

install_textpack(
	'#@admin
	#Strings to default/current language
	msd_google_map_label => Map
	msd_google_map_lookup => Address lookup
	msd_google_map_button => Lookup
	#Additional languages
	#@language en-gb
	msd_google_map_label => Map
	msd_google_map_lookup => Address lookup
	msd_google_map_button => Lookup
	#@language fi-fi
	msd_google_map_label => Kartta
	msd_google_map_lookup => Osoitehaku
	msd_google_map_button => Hae'
);

Or plugin authors can distribute language files (or language plugins/libraries) alongside plugins. And also site authors itself can freely modify text strings to fit their own system.

For even greater experience, that call can be compained with install callback introduced in latest TXP versions.

The system can also be used to add text strings to frontend pages. For some it might be easier to modify short strings from language db than from Templates. And also Template/theme authors can distribute their themes with multiple languages.

Last edited by Gocom (2010-03-03 22:02:06)

Offline

#10 2010-03-04 05:52:27

wet
Developer
From: Lenzing, Austria
Registered: 2005-06-06
Posts: 3,267
Website

Re: Textpacks: I18N facility for plugins and other third party software

Gocom wrote:

Plugin authors can install language strings from a plugin…

I think this should be easier.

A plugin author would embed her Textpack in the plugin’s metadata and let the core do rest upon installation:

<?php

$plugin['version'] = '0.1';
$plugin['author'] = 'Donald Swain';
$plugin['author_uri'] = 'http://codeispottery.com/';
$plugin['description'] = 'Zero use plugin';

$plugin['textpack'] = <<< EOT
#@public
#@language en-gb
foo_hello_world => Hello World!
foo_donald_says => I enjoy your site very much.
# comment line
#@language de-de
foo_hello_world => Hallo Welt!
foo_donald_says => Ich schätze Ihre Site außerordentlich.
EOT;

@include_once('zem_tpl.php');
[...]
echo gTxt('foo_donald_says');
[...]

Additionally, plugin authors or third party translators can distribute Textpacks as standalone files for users to paste into the Preferences > Language tab’s “install_textpack” textarea at their sites. The method of distribution depends on whether a plugin author has the language knowledge and/or capacity to embed any translation into her own code, or rather relies on volunteers for translation contribs and distribution.

Offline

Board footer

Powered by FluxBB