"my multilingual website with only basic php (without zend_translate, gettext, etc…) will i have problems in the future?" Code Answer

3

first off all, it will not work with your code. you would have to use

define('greeting', 'hello world').

check the php manual for define.

second, using contants for this is a horrible idea. you are littering the global namespace with tons of constants and risk constant nameclashing. see the userland naming guide.

if you do not want to use zend_translate (you don't have to use the entire framework for this) and cannot use gettext, i suggest you use arrays for storing the translations, e.g. something like this:

$lang = array(
    'greeting'  => 'hello world'
    'something' => 'else'
);

and then you can use it like this in your template:

<h1><?php echo $lang['greeting'] ?></h1>

this way, you only have to make sure, $lang is not already defined in the global scope.

some people prefer to use the default language instead of translation ids, e.g. they prefer to write

<h1><?php echo t('hello world') ?></h1>

where t would function mapping the input string to the output string. the translation array would have to contain the full sentences then and map these to the other languages, e.g.

$lang = array(
    'hello world' => 'hola mundo'
);

but of course, you could just access this with $lang['hello world'] as well. it just gets awkward for long strings. many translation functions allow you to pass in additional params though, to allow for something like this:

$lang = array(
    'currenttime' => 'the current time is %s'
);

<h1><?php echo t('currenttime', date('h:i:s')) ?></h1>
By Rikesh on June 27 2022

Answers related to “my multilingual website with only basic php (without zend_translate, gettext, etc…) will i have problems in the future?”

Only authorized users can answer the Search term. Please sign in first, or register a free account.