Bi-lingual project
3 years ago
3 years ago
#1
I am trying to get something going to help with having the project bi-lingual I call these language changing functions by URL and they seem to work - at least they are invoked. The last one I am having more problems with. It seems to only return 'is'. Also - as this is a functionality I want to access globally- what would be the best way to call these functions?
3 years ago
#2
Hi thrandur,
I'm afraid I don't know enough to answer your second question about global usage.
However, for your first question, I was not able to reproduce the issue you describe, which makes me think that maybe there's something specific to your environment that is interfering? Either that or I've misunderstood your question, in which case I apologize.
In an existing Trongate project, I placed the code snippet you shared in: modules/language/controllers/Language.php
In Language.php, I made the following changes:
--I added the PHP opening tag at the top
--I changed the return statements to echo.
Checking the Storage > Cookies tab in my browser's developer tools, I confirmed the following:
--Navigating to BASE_URL/language/english sets a 'language' cookie with a value of 'en'
--Navigating to BASE_URL/language/islenska sets a 'language' cookie with a value of 'is'
--Navigating to BASE_URL/language/get_language after performing either of the above steps echoed the expected value, 'en' or 'is'.
I switched back and forth between the two languages a few times without issue.
Hope this helps
I'm afraid I don't know enough to answer your second question about global usage.
However, for your first question, I was not able to reproduce the issue you describe, which makes me think that maybe there's something specific to your environment that is interfering? Either that or I've misunderstood your question, in which case I apologize.
In an existing Trongate project, I placed the code snippet you shared in: modules/language/controllers/Language.php
In Language.php, I made the following changes:
--I added the PHP opening tag at the top
--I changed the return statements to echo.
Checking the Storage > Cookies tab in my browser's developer tools, I confirmed the following:
--Navigating to BASE_URL/language/english sets a 'language' cookie with a value of 'en'
--Navigating to BASE_URL/language/islenska sets a 'language' cookie with a value of 'is'
--Navigating to BASE_URL/language/get_language after performing either of the above steps echoed the expected value, 'en' or 'is'.
I switched back and forth between the two languages a few times without issue.
Hope this helps
3 years ago
#3
Huge thanks for your input!
This led me to the problem :)
It seems there where two language cookies - one of them probably from an earlier attempt. After deleting the correct one everything works just as it should.
This led me to the problem :)
It seems there where two language cookies - one of them probably from an earlier attempt. After deleting the correct one everything works just as it should.
3 years ago
#4
Just FYI the cookie issue was a bit more nuanced. It seems I must include the path in the stecookie function. Something like this:
setcookie("language", "is", time()+3600, "/");
setcookie("language", "is", time()+3600, "/");