Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

best way to build a multi-language site with smarty
Goto page Previous  1, 2, 3 ... 12, 13, 14, 15  Next
 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Tips and Tricks
View previous topic :: View next topic  
Author Message
piins
Smarty Rookie


Joined: 22 Mar 2008
Posts: 6

PostPosted: Sat Mar 22, 2008 3:03 am    Post subject: i18n smarty gettext enabled plugin Reply with quote

as promised, the plugin including a tutorial can be found at the
Piins team blog site...

Hope this helps. Comments are heartily welcome.

cheers,
Charly
Back to top
View user's profile Send private message
zaaas
Smarty n00b


Joined: 22 Mar 2008
Posts: 1

PostPosted: Mon Mar 24, 2008 12:06 pm    Post subject: Re: i18n smarty gettext enabled plugin Reply with quote

piins wrote:
as promised, the plugin including a tutorial can be found at the site...

Hope this helps. Comments are heartily welcome.

cheers,
Charly


im starting a smarty project from scratch and locking for internationalisation. i have tested smarty-gettext. i have some questions.

* what are the general advantages opposite the smarty-gettext plugin?
* is it posible to use mulitple variable placeholders in the message string?
i missed some placeholders in the po file.

Code:
#: templates/smartyVariable.tpl:1
msgid "Displaying a smarty variable: "
msgstr "Hier ist eine Smarty Variable: "


* is it posible to escape variables html/url/nothing?
* what about speed. are there some vantages against smarty-gettext?

Kai[/list]
Back to top
View user's profile Send private message
piins
Smarty Rookie


Joined: 22 Mar 2008
Posts: 6

PostPosted: Wed Apr 02, 2008 3:10 am    Post subject: Re: i18n smarty gettext enabled plugin Reply with quote

zaaas wrote:
im starting a smarty project from scratch and locking for internationalisation. i have tested smarty-gettext. i have some questions.

* what are the general advantages opposite the smarty-gettext plugin?



Hi Kai,

thanks for your interest. The advantages as we see it are:

    * you can use the standard xgettext to extract the strings from the smarty templates, i.e. you can use exactly the same deployment/translation process for your smarty templates as for your php files
    * you can use the same functions for i18n in smarty as you do in php and you don't have to learn an extra syntax
    * you have full plural support
    * you have full smarty variable support, i.e. you can use smarty variables in your smarty templates within the gettext functions and they will be replaced by their values (i.e. you don't have to use the php $smarty->getTemplateVars() function to access the variables)


zaaas wrote:

* is it posible to use mulitple variable placeholders in the message string?


Yes, it easily is possible to use multiple variables in the same string. For that you can have a look at the php printf function, which we support as well.
zaaas wrote:

* is it posible to escape variables html/url/nothing?

It is perfectly possible to escape variables, but I'd recommend to do that in php before you assign the value to the variable, not in the template. You should not really use the template for doing so unless you've got a good reason...
zaaas wrote:

* what about speed. are there some vantages against smarty-gettext?


The speed is roughly the same (well, we claim it's better, but that is our benchmarks on our systems, HP ProLiant Servers Quad-Core, 8 Gb). It definitely can't be worse, because it uses basic functionality, that you use in your php code as well for i18n and smarty templates are compiled.

If you recompile the templates at each step, there might be a performance drawback, but there is no reason to do so, except testing...

If you have time-critical questions, we recommend that you post them on our blog, because we're on it multiple times a day... you don't have to sign up to post a comment, so it should be easy Very Happy

Hope that helped,
Charly
Back to top
View user's profile Send private message
mcdronkz
Smarty Rookie


Joined: 28 Feb 2006
Posts: 8

PostPosted: Sat Apr 19, 2008 9:15 pm    Post subject: Reply with quote

I did the following for my website;

Code:
<p class="title">
{t l=en}Edition of {$smarty.now|date_format:"%d %B %Y"}{/t}
{t l=nl}Uitgave {$smarty.now|date_format:"%d %B %Y"}{/t}
</p>


And then this:

Code:
<?php
function smarty_block_t($params, $content, &$smarty, &$repeat) {
   $lang = new language;
   if($lang->getLanguage() == $params['l']) {
      /*
      Translating months.
      */
      $months['en'] = array("January","February","March","April");
      $months['nl'] = array("januari","februari","maart","april");
   
      /*
      Replace from english to the selected language.
      */
      $content = str_replace($months['en'],$months[$params['l']],$content);
      return $content;
   }
}
?>


Works pretty fine. It handles dates too, as you can see.

Are there any downsides in this in-template approach ?
Back to top
View user's profile Send private message
piins
Smarty Rookie


Joined: 22 Mar 2008
Posts: 6

PostPosted: Sat Apr 19, 2008 10:50 pm    Post subject: open source i18n smarty library Reply with quote

Quote:

Works pretty fine. It handles dates too, as you can see.

Are there any downsides in this in-template approach ?


Hi mcdronkz,

there are some downsides with this approach. One is that you don't really have plural support. As well you'd have to give your tpl files to your translators at some point, and you don't really like them to be dealing with non-standard conform formats, because this obviously can be a huge cost driver. Our system is completely (x)gettext compatible and internationally supported. You can read about it here: blog DOT piins DOT com/2008/03/first-piins-os-release-smarty-i18n.html and see a demo here: blog DOT piins DOT com/api/smarty_i18n/index.php

The full source code is downloadable from the site as well. If you have any questions, just give a shout.

All the bests,
Charly
Back to top
View user's profile Send private message
mcdronkz
Smarty Rookie


Joined: 28 Feb 2006
Posts: 8

PostPosted: Sun Apr 20, 2008 12:03 am    Post subject: Reply with quote

Your system looks very good, but I think it's a bit overkill for my website. I'd like to have everything as lightweight as possible (except for the templateparser), and everything is custom made and scaled down to the purposes of the website.

I've been looking for a gettext solution like yours, which is a very robust solution, but I think my approach has a little better performance and is easier to implement.

But I will dive into i18n !
Back to top
View user's profile Send private message
piins
Smarty Rookie


Joined: 22 Mar 2008
Posts: 6

PostPosted: Sun Apr 20, 2008 12:09 am    Post subject: Reply with quote

Hi mcdronkz,

perfect. As you pointed out, our system might be an overkill for specific purposes. We've developed it for sites, that have to scale to many languages and scale very fast for a big user-base...

If you're diving into i18n and should have any questions, we're also happy to help you wherever we can Smile, we've gone through this process ourselves and would love to share the knowledge we gathered there..

Wish you best luck!

Charly
Back to top
View user's profile Send private message
Skull88
Smarty n00b


Joined: 17 May 2008
Posts: 1

PostPosted: Sat May 17, 2008 6:39 pm    Post subject: Reply with quote

Hey,

I don't have much experience with smarty, actually the first time I do something in it. But I want a premade script which uses the smarty engine to be multi-language. I've managed to get the SmartyML class to work but I have one problem. I have made 2 folders a English one and a Dutch one, when I view the site it is showing the Dutch language which is correct. And when I specify in the index to show the English language it shows the English so that is also OK. But when I now delete or rename the Dutch folder to see if when someone with a not supported language comes on the site is seeing the English version (it is supposed to do that not? Or am I misinterpreting the following: $this->_defaultLocale = 'en'; ) I've tried to delete the dutch language in the language table but that didn't worked.
Is there something I've got to do, to make it that when someone with an unsupported language visits the site that it shows the site in English?

tnx in progress Smile
Back to top
View user's profile Send private message
piins
Smarty Rookie


Joined: 22 Mar 2008
Posts: 6

PostPosted: Tue May 20, 2008 12:09 am    Post subject: Reply with quote

Skull88 wrote:
Hey,

I've tried to delete the dutch language in the language table but that didn't worked.
Is there something I've got to do, to make it that when someone with an unsupported language visits the site that it shows the site in English?

tnx in progress Smile


hi Skull88,

usually this should exactly accept the default as you suggested. Instead of deleting the Dutch language you could just reset your browser language or use a custom language header (Accept-Language header):

Accept-Language: en-us,en;q=0.5

->

Accept-Language: de-AT,de;q=0.5

for German in Austria....


Your procedure seems right to me tho.

If you like, you can also try our i18n library. It's used already on some Chinese and Arabic sites, so it should work with dutch as well. We are using it ourselves for French, Islandic, Hungarian, German and English Smile Happy to help you with that one at any time.

Little demo/tutorial is on: http://blog.piins.com/api/smarty_i18n/index.php

Bests,
Charly
Back to top
View user's profile Send private message
StNick
Smarty Rookie


Joined: 30 May 2008
Posts: 5

PostPosted: Mon Jun 02, 2008 7:50 am    Post subject: Reply with quote

Firstly, let me apologise in advance for asking this question on the Smarty forums, as this is really a "gettext" query. However, this thread in particular has been a HUGE help to me in making my application multilingual, so I am hoping that there is a simple answer right here.

So far, I've got gettext working great, along with smarty-gettext. Can someone tell me how I would use gettext to pick up strings with variables?

For example, I pass a string to my feedback class like so...

Code:
$feedback->notice("User '$username' already logged in");


So for gettext, I thought I'd just use:

Code:
$feedback->notice(_("User '$username' already logged in"));


But alas, this doesn't work (for obvious reasons when I think about it). I suppose I could split it into two strings like so:

Code:
$feedback->notice(_("User") '$username' _("already logged in"));


However, this might not make sense in certain languages. Any help/ideas appreciated. Thanks!
Back to top
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Mon Jun 02, 2008 10:29 am    Post subject: Reply with quote

sprintf() would be an option (and it would be AFAIK the recommended approach if you used gettext in C where it originally came from).

Code:
$feedback->notice(_("User '%s' already logged in"), $username);
Back to top
View user's profile Send private message Send e-mail Visit poster's website
itwebteam
Smarty n00b


Joined: 26 Sep 2004
Posts: 3

PostPosted: Sun Jun 08, 2008 10:09 pm    Post subject: Reply with quote

Hi guys.
does anyone have a version of tsmarty2c.php for windows?
thanks a LOT
Back to top
View user's profile Send private message
tobias.schittkowski
Smarty n00b


Joined: 24 Jun 2008
Posts: 1

PostPosted: Tue Jun 24, 2008 8:37 am    Post subject: Some simple and effective way for i18n Reply with quote

Hi!
I simplified andre's approach, what is you opinion?

www.schittkowski.de/index.php?q=node/20

The tokens which have to be translated should be enclosed by @@ and i use one translation file per language...

Any comments are welcome!

Tobias
Back to top
View user's profile Send private message
Eviang
Smarty n00b


Joined: 12 Mar 2009
Posts: 1

PostPosted: Thu Mar 12, 2009 10:03 am    Post subject: how can I have dinamic content based on page selection? Reply with quote

Hello everyone,

I'm just discovering Smarty and found these classes from André which are pretty cool and clean. My question is for him presicely:

The site I'm making uses the same header.tpl for every page, but I want the title to change accordingly and also in different languages. I've been having trouble with letting your classes know which title to load depending which page I'm calling (i.e. Home for main.tpl, Products for products .tpl, etc).

I have no problem in changing languages and using simple text files as language templates but when I do something like:
Code:
<?php

include('plugins/function.multilinguage.php');

// create object
$smarty = new SmartyML();

$title_page = ##NG_TITLE_HOME##;

$smarty->assign('title', $title_page);

$smarty->display('header.tpl');

?>

it doesn't work... I've tried in many many different ways and nothing. The best result I had was ##NG_TITLE_HOME## in the title Sad

In this example I'm calling the translation of NG_TITLE_HOME instead of i.e. NG_TITLE_PRODUCTS because after header.tpl, I'm going to call main.tpl

How can I acchieve this?

Thanks in advance!

EDIT: I found another thing that's not working and it's pissing me off! When I change one translation, it won't refresh on the site no matter what. I've tried by setting Smarty cache to 0 and also to 2 with a lifetime of 10 seconds and nothing!!! How can I fix this?

Thanks again Very Happy
Back to top
View user's profile Send private message
Viruz
Smarty Rookie


Joined: 05 May 2008
Posts: 10

PostPosted: Thu May 28, 2009 4:44 pm    Post subject: Reply with quote

sind hier eventuell deutsche die mir weiterhelfen können? ^^
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Tips and Tricks All times are GMT
Goto page Previous  1, 2, 3 ... 12, 13, 14, 15  Next
Page 13 of 15

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP