xfra35 / f3-multilang Goto Github PK
View Code? Open in Web Editor NEWCreate multilingual apps with this localization plugin for the PHP Fat-Free Framework
License: GNU General Public License v3.0
Create multilingual apps with this localization plugin for the PHP Fat-Free Framework
License: GNU General Public License v3.0
I'm trying to use F3 in an existing project, writing new modules with F3 and slowly migrating old ones.
We have a language switch on the website which sets the language in session, so I read that and pass it to F3 after reading my config.ini
// set language to the one user selected
if ($_SESSION['sprache'] == 'de') {
$f3->set('LANGUAGE', 'de');
}
else {
$f3->set('LANGUAGE', 'en');
}
I started using multilang today, so I might be wrong, but it seems like my manually set language is ignored by multilang and it always detects my german browser language.
Do you have any ideas what could have gone wrong in this case?
Kind regards
Frank
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');
Hi, I assumed that setting $global as an array of aliases ['adm_login','adm_dash'] would skip the Multilang rewrite but no, I get 404 for /admlogin and 200 for /en/admlogin.
How would I accomplish this without manually rewritting routes ?
Thank you for your time.
Hi,
I am addind this plugin to an existing fatfree installation.
How can I redirect the old urls to the default language?
Example
domain.com/old/route/app should be redirected to
domain.com/en/old/route/app
but this should not be redirected because it works by default:
domain.com/es/old/route/app
Thanks
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?
Imagine that I have a backoffice, in my backoffice urls I don't want the language prefix to appear.
For example:
-Public url:
http://www.example.com/en/contacts
http://www.example.com/pt/contactos
http://www.example.com/en/portfolio
http://www.example.com/pt/portfolio
-Backoffice url:
http://www.example.com/admin/users
http://www.example.com/admin/news
http://www.example.com/admin/configs
Hey there,
Just was messing with this today and I had 2 routes that pointed to the same endpoint, but had different aliases. Multilang was not a fan haha.
GET @companies: /companies = Company->indexAction ; routes to /en/companies
GET @companies_create: /companies/create = Company->createAction; routes to /en/companies/create
POST @companies_handle_create: /companies/create = Company->handleCreateAction; ERROR routes to /companies/create
Without doing a ton of digging, I'm better the problem lies in the rewrite()
method in Multilang. Don't know if this is a feature or a bug, please advise 😄
Hey,
I've seen your great demo of the plug-in, but I'm wondering how you dynamically build links to change the language while staying on the same page (the flags on top of the page).
What I mean is if I'm on the /en/contact/ page, how can I make a /fr/contact link on the template ?
Thanks in advance for your answer =)
Hi,
I am trying to make this work:
From here:
http://fatfreeframework.com/routing-engine
$f3->redirect('GET|HEAD /obsoletepage', '/newpage');
And the problem is that the obsolete page is not working because it has the language before it.
/en/obsoletepage
So it does not redirect.
Any ideas?
Thanks!
Big fan of your work guys, thank you.
My issue, I was wondering if I could do it in the f3 "way" without a custom route controller
I wish to have an optional selected region added in the url
For example Is possible to implement ?
/fr/* as /fr-CH/* or /fr-FR/*
where $CH or $FR could be a default $WW (for world wide)
Hi, how are you?
Is there an option to hide the default language from the url?
Imagine a portuguese app, but also has english translation. 85% of the users are portuguese and 15% aren't. Would make sense to hide /pt
since 85% users are portuguese and seeing that in the URL will not matter. Or in the case that I'm building an app that currently supports one language only (but in a near future could turn multilang), so I use Multilang Class thinking about the possibility of having a new language added in the future. If this is the case, all my urls will show /pt
although my website only has Portuguese at the moment.
Example urls:
https://my-app.com/ (Portuguese)
https://my-app.com/users (Portuguese)
https://my-app.com/books (Portuguese)
https://my-app.com/books/1 (Portuguese)
https://my-app.com/en (English)
https://my-app.com/en/users (English)
https://my-app.com/en/books (English)
https://my-app.com/en/books/1 (English)
Its probably an aesthetic question, but would be nice to see this implemented. (Since I've faced this problem already).
Cheers.
How can I ignore a whole folder on the global config?
I would like to keep all the routes under /api/* without using the language reroute.
Thanks
Hey there xfra35,
I've been using this library with the migrate option enabled and recently the redirects began being made to:
/lang/somepath/@someparam
When it previously would redirect to:
/lang/somepath/theactualparam
That is, it redirects to a route without replacing the placeholder with the actual parameter.
Please see the screenshot from devtools where you can see the "Location" header redirecting to a route without substituting the route parameter with the actual variable.
I'm guessing this is happening since this change. At least if I use a base.php file before that I get the correct behavior.
Cheers
Hi,
On global routes, multilang detects the browser language and loads it.
The problem is that it is not working properly I think.
I have my browser options setup to use Spanish and other browser on english.
Both appear with the english options on you demo:
http://ml.aesx.fr/en
(sidebar information).
It looks like it consider the installation language and not the language set on options on the browser.
Why not use the fallback language on fatfree when the route is global?
I use f3-Multilang on most public sites and I exclude a few sites that are for logged in users like admins.
after the last update, I have the following problem. I use an ONREROUTE rule to ml reroute if needed.
$f3->set( 'ONREROUTE', function ($url, $permanent) use ($f3, $ml) {
if (!$ml->isGlobal( $url ) && !in_array( $url, $f3->get( "excludedRedirects" ) )) {
$f3->clear( 'ONREROUTE' );
$ml->reroute( $url, $permanent );
}
else {
return false;
}
} );
this way I can still use f3 reroute without sending the language.
After the latest F3 update the following problem happens:
whenever a reroute happens to a dynamic URL the URL in ONREROUTE doesn't have the "REAL" URL but the URL with the params.
so let's say I got the URL
/blog/@article
so normally if i would reroute to (or someone links links to)
/blog/1
it should be sent to /en/blog/1
but suddenly I get errors. I traced it down to f3-Multilang being active and ONREROUTE.
the $url Variable in the OnReroute Function will suddenly say:
/blog/@article
instead of /blog/1
Wish to have this option you have described in the google-group under https://groups.google.com/d/msg/f3-framework/NAhOB6rL6sw/4YpQ4OPT900J
It would be great.
Thanks
Hello mate,
does rerouting function from f3 conflicts with multilang?
I got this line of code:
$f3->reroute('/'.$route);
This reroutes to app-path.com/route
insted of app-path.com/en/route
.
Should I use?
$f3->reroute('/'.$m->current().'/'.$route);
It was nice if this was automatically ;)
Thanks for your time,
cheers.
Hi,
I've setup the following route:
GET|POST @userrequest : /profile/@action=UserControl->@action
Now, i'm trying to pass the @action param (edit) within the alias function inside my view:
<a href="{{ $ml->alias('userrequest','edit',$ml->current) }}">Edit profile</a>
The current output is:
<a href="/profile/@action">Edit profile</a>
I was expecting the result to be:
<a href="/profile/edit">Edit profile</a>
my single route with @action should handle UserControl->edit & update & cancel & emailupdate.
Is the Alias/param var used for this purpose? Is it a bug? Can this param be localized (i.e French = edtion & mise-a-jour & supprimer & mise-a-jour-email? What I'm missing?
Hi, i hope that the url format is not /xx/user
but /user?lang=xx
.
and then, the ?lang=xx
is can be removed as it was saved into cookie. So user can acces other page on the same Language.
Eg. /about
without need to specify ?lang=xx
again after accessing /user?lang=id
(User no need to access this way: /about?lang=id
.
Thankyou!!
Hi I am using fabulog and I can't seem to add both /admin and /login to the global ignore list, can you tell me how do I do that? Below's my config.ini:
menu = about, press, news, terms, privacy, contact, login, admin
[maps]
@about : /about = Controller\About
@press : /press = Controller\Press
@news : /news = Controller\News
@terms : /terms = Controller\Terms
@privacy : /privacy = Controller\Privacy
@contact_add : /contact/add = Controller\Contact->addContact
@contact_alert : /contact/alert = Controller\Contact->alert
@image_download : /download/@image = Controller\Press->imageDownload
@login : /login = Controller\Auth->login
@admin : /admin = Controller\Dashboard->main
[MULTILANG]
global = terms, privacy, /admin/post, contact_add, contact_alert, image_download, login, admin
[MULTILANG.languages]
en = en-GB, en-US, en
tw = zh-TW, tw
[MULTILANG.rules.en]
admin_create = /admin/@module/create
contact_add = /contact/add
contact_alert = /contact/alert
image_download = /download/@image
admin = false
login = false
[MULTILANG.rules.tw]
admin_create = /admin/@module/create
contact_add = /contact/add
contact_alert = /contact/alert
image_download = /download/@image
Seems both rewrite the $f3->ROUTES and can't figure which one to load and run first, not mention i'm also using f3-events, my project starts to turn into a mess.
Seems I have to use the full route with language for middleware to detect..
\Middleware::instance()->before('GET /en-GB/user'..
Moving the \Multilang initialization before/after/between the middleware on/run has no effect.
Let's say we want the language menu to take you to the same page in the other languages, no just the root of the language.
Example:
You're on /en/games/first-person
and this route is defined as follows:
GET @gamessection: /games/@section = Controller\Games->section
The corresponding rule for Spanish looks like this:
[MULTILANG.rules.es]
gamessection = /juegos/@section
The language menu looks like this:
<a title="GamesSite - English" href="{{@ml->alias(@ALIAS, null, 'en')}}">English</a>
<a title="GamesSite - Español" href="{{@ml->alias(@ALIAS, null, 'es')}}">Español</a>
The URL for Spanish will be rendered as /es/juegos/first-person
when what we want is /es/juegos/primera-persona
. How do we localise the @section
parameter as well as the fixed part of the URL?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.