Sophie

Sophie

distrib > Mageia > 4 > x86_64 > by-pkgid > fe4c33da796ffc06aec2912abfb21fce > files > 3

php-smarty-gettext-0.9.1-4.mga4.noarch.rpm

Gettext support for Smarty
--------------------------
$Id: README,v 1.2 2004/04/30 11:39:53 sagi Exp $

Author: Sagi Bashari <sagi@boom.org.il>
URL: http://smarty-gettext.sf.net/

This file assumes that you already know what is gettext and how to use it with PHP. 
If you don't, please visit the following websites before trying to use this package:
  - http://www.php.net/gettext
  - http://www.onlamp.com/pub/a/php/2002/06/13/php.html

This package has two parts:
  1. smarty-gettext.php - The smarty plugin
  2. tsmarty2c.php - command line utility that rips gettext strings from smarty source files and converts them to C format

The Smarty plugin
-----------------

Installation:

1. Copy the smarty-gettext.php file to your include directory. 
2. After initializing the smarty object in your script, register the plugin as a block function.

Example:
$smarty = new Smarty [...];
require('smarty-gettext.php');
$smarty->register_block('t', 'smarty-translate');

This example will register the function as a block function named 't'.

Usage:

The content of the block function is the string that you want to translate. For example, for translating 'Hello World', use: {t}Hello World{/t}.

If you have dynamic parameters that should be set inside the string, pass them to the block function, and they will be replaced with %n, where n is 1 for the 1st parameter and so on. For example, {t name="sagi"}my name is %1{/t} will replace %1 with name.

The parameter name is ignored, unless it is one of the reserved names (see below). Only the parameters order matters.

Example for using multiple parameters:
{t 1='one' 2='two' 3='three'}The 1st parameter is %1, the 2nd is %2 and the 3nd %3.{/t}

NOTE: I decided to use numeric arguments instead of sprintf(), because it offers greater control over the parameter placement in the translated text. You can also use this in your PHP code, by using the strarg() function, like this: strarg(_('hi %1'), $name [,..]).

By default all the translated strings will be automatically HTML escaped. You may control this by setting the 'escape' parameter. Possible values:
  - 'html' for HTML escaping, this is the default.
  - 'js' for javascript escaping.
  - 'no'/'off'/0 - turns off escaping

  Example: {t escape=no url="http://www.php.net/" name="PHP website"}<a href="%1">%2</a>{/t}

Plural support:

The package also provides support for plural forms (see ngettext). 

To provide a plural form:
  1. Set a parameter named 'plural' with the plural version of the string.
  2. Set a parameter named 'count' with the variable count.

Example:
{t count=$files|@count plural="%1 files"}%1 file{/t}


tsmarty2c.php - the command line utility
----------------------------------------

This utility will rip the translation strings from the smarty files, and convert them to gettext calls in C, that can later be used with the standard gettext tools.

Usage:
./tsmarty2c.php <filename or directory> <file2> <..> > smarty.c

If a parameter is a directory, the template files within will be parsed.

Copyright
---------

Copyright (c) 2004 Sagi Bashari

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA