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

Multi Langue avec Smarty

 
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 -> Language: French
View previous topic :: View next topic  
Author Message
Guillaume
Smarty n00b


Joined: 07 Jul 2008
Posts: 1

PostPosted: Mon Jul 07, 2008 3:31 pm    Post subject: Multi Langue avec Smarty Reply with quote

Bonjour,

J'attaque la création d'un site avec Smarty, et j'aimerai qu'il soit multilangue, savez-vous comment partir : faut-il utiliser la base de données ou plutot les fichiers XML ? Y a t'il quelque chose dans Smarty qui facilite ca ?

J'ai vu dans la doc de Smarty qu'apparemment il peut y avoir dans les plugins une fonction de blocs qui peut permettre cela ? Avez-vous déja essayé ?

Merci !!
Back to top
View user's profile Send private message
reb
Smarty Rookie


Joined: 17 Aug 2005
Posts: 23

PostPosted: Mon Jul 07, 2008 5:40 pm    Post subject: Reply with quote

J'utilise un "fichier de configuration" par langue : un simple fichier texte avec les traductions. Cf. http://www.smarty.net/manual/fr/language.config.variables.php

ex :
Une recherche de la langue préférée se fait dans le fichier PHP. Ex :
Code:
$_SESSION['strLangue'] = 'fr';
$smarty->config_dir  =  'lang/';


/lang/fr/lang.txt
Code:
nomSite=Mon site web


lang/en/lang.txt
Code:
nomSite=My website


Et dans le template
Code:
{config_load file="`$smarty.session.strLangue`/lang.txt"}
<h1>{#nomSite#}</h1>


Last edited by reb on Wed May 05, 2010 10:34 pm; edited 1 time in total
Back to top
View user's profile Send private message
mumuri
Smarty Rookie


Joined: 06 Apr 2008
Posts: 27

PostPosted: Sun Jul 13, 2008 4:24 pm    Post subject: Reply with quote

si tu regardes dans zikula (qui utilise smarty)

il ont un smarty pnml

Quote:
Example _EXAMPLESTRING = 'Hello World' {pnml name="_EXAMPLESTRING"} returns Hello World

_EXAMPLESTRING = 'There are %u% users online'; $usersonline = 10 {pnml name=_EXAMPLESTRING u=$usersonline} returns There are 10 users online


qui charge des constantes de fichier de configuration prédéfini, ensuite il doivent charger le bon fichier de configuration au chargement de la page
Back to top
View user's profile Send private message Visit poster's website
gtraxx
Smarty Regular


Joined: 08 Jan 2008
Posts: 56

PostPosted: Tue Aug 05, 2008 11:06 am    Post subject: Reply with quote

reb ta méthode est très bien mais comment l'adapter avec un GET au lieux d'une session.
Genre je clique sur fr pour charger la config française
Back to top
View user's profile Send private message
reb
Smarty Rookie


Joined: 17 Aug 2005
Posts: 23

PostPosted: Sat Aug 09, 2008 5:07 pm    Post subject: Reply with quote

gtraxx wrote:
reb ta méthode est très bien mais comment l'adapter avec un GET au lieux d'une session.
Genre je clique sur fr pour charger la config française


Pareil :

Code:
$_GET['strLangue'] = 'fr';


La session c'est pratique car comme ça, tu garde le choix en mémoire. L'exemple était très simplifié ; le choix de la langue peut venir d'un GET, d'une préférence en SGBD, d'un paramètre de l'application,...

On pourrait avoir :

Code:

if (empty($_SESSION['strLangue']) || !empty($_GET['strLangue'])) {
  $_SESSION['strLangue'] = empty($_GET['strLangue']) ? 'fr' : $_GET['strLangue'];
}


comme ça on a une langue par défaut si rien n'est précisé. Si on a déjà la langue choisie (en session) on peut la modifier via une variable en GET


Last edited by reb on Wed May 05, 2010 10:34 pm; edited 1 time in total
Back to top
View user's profile Send private message
gtraxx
Smarty Regular


Joined: 08 Jan 2008
Posts: 56

PostPosted: Sat Aug 09, 2008 11:53 pm    Post subject: Reply with quote

c'est vrai que c plus pratique d'utilisez cette méthode pour les parties static un fichier .conf pour charger la langue des menus, des textes static, etc ..
je vais tester avec ton exemple
mais une derniere question, au lieux d'un seul fichiers texte comment attribuer par exemple en.txt pour l'anglais, fr.txt , etc ..
Donc un fichiers de config par langue
merci
Back to top
View user's profile Send private message
reb
Smarty Rookie


Joined: 17 Aug 2005
Posts: 23

PostPosted: Sun Aug 10, 2008 12:08 pm    Post subject: Reply with quote

Pareil :

Code:
{config_load file="`$smarty.session.strLangue`.txt"}


en ayant précisé au départ l'emplacement des fichiers conf., par exemple :

Code:
 $smarty->config_dir = '/chemin/vers/lang/';


Last edited by reb on Wed May 05, 2010 10:34 pm; edited 1 time in total
Back to top
View user's profile Send private message
gtraxx
Smarty Regular


Joined: 08 Jan 2008
Posts: 56

PostPosted: Tue Aug 19, 2008 4:36 pm    Post subject: Reply with quote

Sa marche parfaitement, je pense réaliser un petit plugin a l'occasion
Wink merci
Back to top
View user's profile Send private message
mhurier
Smarty n00b


Joined: 20 Aug 2008
Posts: 4

PostPosted: Wed Aug 20, 2008 1:52 pm    Post subject: Reply with quote

cool merci ca ma servit
Back to top
View user's profile Send private message
djkost85
Smarty Rookie


Joined: 24 Dec 2008
Posts: 5

PostPosted: Wed Dec 24, 2008 2:22 pm    Post subject: Reply with quote

thnks
Back to top
View user's profile Send private message
djazzc
Smarty n00b


Joined: 10 Aug 2009
Posts: 3

PostPosted: Mon Aug 10, 2009 5:06 pm    Post subject: smarty multi language Reply with quote

@reb merci beaucoup, ca marches niquel!! Very Happy
Back to top
View user's profile Send private message
gtraxx
Smarty Regular


Joined: 08 Jan 2008
Posts: 56

PostPosted: Mon Feb 22, 2010 9:56 am    Post subject: Reply with quote

Bonjour je tiens à préciser que cette méthode fonctionne bien avec smarty 3 seulement la fonction config_load déconne de temps en temps dans smarty 3 (probléme de compilation peut être)
Est ce du a l'encodage des fichiers de configuration ou peut être la syntaxe ?
Sans oublier que les commentaires avec # sont bien pris en charge mais pas les ####
Bref je retourne le tout dans tous les sens afin que tout sois parfais avec notre cher smarty qui grandi bien Very Happy
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 -> Language: French All times are GMT
Page 1 of 1

 
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