xfra35 / f3-multilang

Create multilingual apps with this localization plugin for the PHP Fat-Free Framework
GNU General Public License v3.0
48 stars 13 forks source link

I can't seem to make multilang to work with the backend of fabulog #9

Closed zeon closed 8 years ago

zeon commented 9 years ago

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');

xfra35 commented 9 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:

Remember that rewritten URLs are restricted by the framework to latin letters without diacritics. So :

UPDATE: This restriction is now removed: https://github.com/bcosca/fatfree-core/pull/71

ikkez commented 9 years ago

@zeon, translating backend routes doesn't look that useful to me ^^ but it would be nice for the frontend blog posts, indeed.

Norcoen commented 8 years ago

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.

xfra35 commented 8 years ago

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
Norcoen commented 8 years ago

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

xfra35 commented 8 years ago

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