Closed zeon closed 8 years ago
Hey @zeon,
In order for URL rewriting to work you need to name routes.
Let's take the case of the first route: GET /admin/@module/create
.
You need first to give a name to this route, e.g "admin_create". So L85 of index.php becomes:
$f3->route('GET @admin_create: /admin/@module/create', 'Controller\Backend->getSingle');
Then you can rewrite this route in config.ini:
[MULTILANG.languages]
fr = fr-FR, fr
en = en-GB, en
[MULTILANG.rules.fr]
admin_create = /admin/@module/ajouter
Now instead of /admin/@module/create
, we have:
/fr/admin/@module/ajouter
/en/admin/@module/create
Remember that rewritten URLs are restricted by the framework to latin letters without diacritics. So :
/fr/admin/@module/creer
works/fr/admin/@module/créer
doesn't/zh/admin/@module/tianjia
works/zh/admin/@module/添加
doesn't/ru/admin/@module/dobavit
works/ru/admin/@module/добавить
doesn'tUPDATE: This restriction is now removed: https://github.com/bcosca/fatfree-core/pull/71
@zeon, translating backend routes doesn't look that useful to me ^^ but it would be nice for the frontend blog posts, indeed.
Is it possible to translate @-tokens? I have /@module/@controller/@action/* and I would like to translate /en/plan/trains/list/etc/pp to /de/plan/zuege/liste/etc/pp
but F3 trys to call zuege->liste() in this case.
That's not part of the plugin as tokens are usually meant for app data (think of a blog entry title for example) and app data is usually translated in database.
But what you're asking for should be easy to implement with a dictionary.
Something like this:
$f3->route('GET /@module/@controller/@action/*',function($f3,$params){
list($uri,$module,$controller,$action,$data)=$params;
$dict=$f3->get('DICT');
foreach(array('module','controller','action') as $k)
if ($term=@$dict[$k.'s'][$$k])
$$k=$term;
$f3->call("$module\$controller->$action",array($f3,$params));
});
with a dictionary looking like:
;de.ini
[modules]
foo=plan
[controllers]
zuege=trains
[actions]
liste=list
Thank you! Works fine with your code.
I usually have all my routes in .ini files, do I need to move them into my index.php (or require another .php with route declarations) or is there a way to achieve this in my .ini file?
Right now I just call a new class I created, which has only one function with your code instead of directly calling my module->function
If you've made a new class for that snippet, then just call it from the ini file:
[routes]
GET /@module/@controller/@action/* = myClass->myMethod
can you give some hints on how to write the mappings in the config.ini when f3 routes are like this:
$f3->route('GET /admin/@module/create', 'Controller\Backend->getSingle'); $f3->route('POST /admin/@module/create', 'Controller\Backend->post'); $f3->route('GET /admin/@module/edit/@id', 'Controller\Backend->getSingle'); $f3->route('POST /admin/@module/edit/@id', 'Controller\Backend->post');