Closed eliogsolis closed 8 years ago
Hi,
In order to define a dictionary, you should follow the steps below:
dict/
) with a dictionary file for each supported language. For example, en.ini
, nl.ini
and zh.ini
for English, Dutch and Chinese. Each dictionary file contains a list of key-value pairs, such as hello = 你好
.$f3->LOCALES='dict/';
$f3->LANGUAGE='zh';
echo $f3->hello
outputs 你好
NB1: when using the Multilang
plugin, step 3 is automatically handled by the plugin (language is detected from the URI).
NB2: you can automatically prefix all dictionary entries. For example:
$f3->PREFIX='DICT.'
will store the previous entry to $f3->DICT['hello']
$f3->PREFIX='dict_'
will store it to $f3->dict_hello
See the framework documentation for more details.
Not working for me My index.php
require('vendor/autoload.php');
$f3=Base::instance();
$f3->config('app/config.ini');
$f3->config('app/routes.ini');
Multilang::instance();
$f3->set('LOCALES','/dict');
$f3->set('PREFIX','dict_');
$f3->run();
My dict/en hello = Hello
and dict/es hello = Hola Controllor just doing an echo $f3->dict_hello;
It should be $f3->set('LOCALES','dict/')
.
Well... actually the plugin is working with URL's
/multilang/es
but still not working in my controller (i made the change that you suggested)
$f3->get('dict_hello');
$f3->get('dict.hello');
$f3->get('DICT.hello');
$f3->dict_hello;
Thanks for the help!! And sorry for my bad english...
What do you mean by "not working"? Does it output an empty string? or a bad translation?
Gettin null from
var_dump($f3->get('DICT.hello'));
or empty if i use an echo
echo $f3->dict_hello;
Try to output $f3->LANGUAGE
just after the plugin instantiation to see if Spanish is detected.
Gettin es-ES,es,en-GB,en,en-US
The detection is correct. So there's an issue with your dictionary files.
You should have:
LOCALES=dict/
PREFIX=dict.
Your folder structure should look like:
app/
dict/
es.ini
vendor/
index.php
es.ini
should look like:
hello = Hola
thanks = Gracias
After which, print_r($f3->dict)
should output an array containing Hola
and Gracias
.
Mmm... (T-T) ... I dont know why its not working for me...
es.ini
my index just in case
my controller
And my config.ini and routes.ini
You don't need to have dict/
in your autoload path.
And in case, it should be AUTOLOAD = "app/;dict/"
otherwise it becomes an array without the " " around it, which could cause misbehaviour for the autoloader, as this is a special edge case for custom autoload functions
@eliogsolis you're defining PREFIX
after loading the dictionary (via LOCALES
), so the term is stored in hello
instead of dict.hello
.
Just reverse the two lines to fix your problem:
$f3->PREFIX='dict.';
$f3->LOCALES='dict/';
I've just added a mention about it in the docs.
@ikkez the issue you're describing occurs with commas, not semicolons. This is because $f3->config
uses str_getcsv
to split values, not $f3->split
.
Anyway thanks for mentioning it. It's good to know that semicolons are safer to use in config files. I've just added a warning for it in the docs.
i saw an example here https://groups.google.com/forum/#!topic/f3-framework/NAhOB6rL6sw
im trying this
{{ @dict.hello }}but it doesnt work, can you help me please?