0

I've just started using smarty but i have some problems to find a proper way for multilanguage scripts.

There are some solutions for this problem, that i found until now.

  1. smarty-gettext this seems like a nice solutions, because translator could easily work with poedit but the plugin wasn't updated since 2005, seems to be outdated.
  2. different templates for each language seems not to be best practice, becaue language and content is no longer split up and adding new languages and updating templates can become a real pain in the a**.
  3. Custom array solutions there are a bunch of solutions like this be they all sound like a quick 'n dirty workaround and are definitely not best practice, i think.

I hope you have some ideas for good solutions.

PeeHaa
  • 71,436
  • 58
  • 190
  • 262
Frederick Behrends
  • 3,075
  • 23
  • 47
  • How deep are you in smarty code? If youre jsut getting started id recommend switching to [Twig](http://twig.sensiolabs.org/) which also has [i18n extension](http://twig.sensiolabs.org/doc/extensions/i18n.html), and since its managed by the Twig core team it shouldnt be out of date unless development of [Twig](http://twig.sensiolabs.org/) ceases all together which is unlikely since its the default template system for Symfony2 – prodigitalson Mar 02 '12 at 20:53
  • I think so. But this is really subjective. Also i should discolose that in general I am still part of the "php is a template language" crowd :-) But Twig hasnt been a headache in the couple [Silex](http://silex.sensiolabs.org/) based projects i've used it on. Also moved my comment to an answer with some reccommends if you want to stick with Smarty. – prodigitalson Mar 02 '12 at 21:01

1 Answers1

1

gettext is definitely the way to go here unless you want to use xliff or something (if thats the case id recommend using Zend_Translate and creating a smarty extension with it as the engine). I would use the existing smarty plugin but fork it so that if you need to update it you can and then contribute those back to the community.

That said, How deep are you in smarty code?

If youre just getting started id recommend switching to Twig which also has i18n extension, and since its managed by the Twig core team it shouldnt be out of date unless development of Twig ceases all together which is unlikely since its the default template system for Symfony2

prodigitalson
  • 60,050
  • 10
  • 100
  • 114
  • Is there a Twig sample script anywhere? To see how to make the first steps and a little of its possibility? – Frederick Behrends Mar 02 '12 at 21:07
  • I think I'm blind, can't find the download link of the i18n extension – Frederick Behrends Mar 02 '12 at 21:21
  • 1
    [Extensions](https://github.com/fabpot/Twig-extensions), [Docs](http://twig.sensiolabs.org/documentation). For what its worth i usually use [Composer](http://packagist.org/) which has [Twig repositories](http://packagist.org/packages/twig/) – prodigitalson Mar 02 '12 at 21:32
  • It's my first time to use a Framework in PHP so i better stick to Twig+extensions and start getting into composer, when i've tested it a bit. – Frederick Behrends Mar 02 '12 at 21:56
  • Template-Framework/Engine, sorry if you named it wrong. I Started using it but, i'm running into trouble with `ngettext` and PoEdit I can not retrieve the strings used by `ngettext` to translate them. Search the whole internet, but can't find a working solution for my windows pc. Additional PoEdit is extremly unstable on windows :( – Frederick Behrends Mar 02 '12 at 22:56
  • Yeah cant help you there, not really a windows user :-) You could set up a *nix virtual machine. Did you see [this](http://stackoverflow.com/questions/3393139/how-to-make-poedit-correctly-parse-custom-ngettext-implementation)? – prodigitalson Mar 02 '12 at 23:30
  • You also might want to post additional specific questions about issues youre having with different pieces of this setup (twig, twig i18n, n/xgettext, poedit, etc.) someone may have the answer :-) – prodigitalson Mar 02 '12 at 23:38