localization issue |
i believe to have an issue like this: https://forum.codeigniter.com/thread-75292.html
I have a site in 3 language: IT EN ES I use {locale} and all work good but only if the pages are identical. For example: in IT and ES i display the "regular home page" but in EN i would like display a maintenance page. Something force the view and too in EN i can see the home in english. My link: mydomain.com/it mydomain.com/es mydomain.com/en EN controller (i tried too with redirect but doesn't work): PHP Code: public function index() IT controller: PHP Code: public function index() Any idea to solve? Thanks for help me.
What about a basic if control ? I use it to check if language segment of my url is empty or not. I have changed my codes for you
PHP Code: public function index(){ I tried checking the language with segment feature but you can check it via localization as well PHP Code: $locale = $this->request->getLocale();
What do you mean by IT controller and EN controller? When using localization you don't need separate controller for each languages. The text is pulled from the language files but the logic in the controller is the same. Is you want different logic for a specific language you do as demyr said. Use getLocale() to make an if statement.
(04-29-2021, 05:16 PM)includebeer Wrote: What do you mean by IT controller and EN controller? When using localization you don't need separate controller for each languages. The text is pulled from the language files but the logic in the controller is the same. Is you want different logic for a specific language you do as demyr said. Use getLocale() to make an if statement. Sorry all logic in one controller? Something like this: PHP Code: class Helloworld extends BaseController and after what is the route for have a link like: www.mydomain.com/en/about-us or www.mydomain.com/it/chi-siamo ? PHP Code: $routes->get('{locale}/about-us', 'Helloworld::about_us'); INSTEAD If i have 2 separate controller can i use localization and placeholder {locale}? Is there a method more correct for this case? A little example: https://drive.google.com/drive/folders/1...sp=sharing Thanks for help me.
You should have a language column on mysql for any table (pages, products, blog etc).
On your controller you can retrieve your datas by using: slug + language, or id + language For example (Controller): Code: public function about_us() Model: PHP Code: public function fetch_page($lang, $page_slug){ + you can name your routes in any language, and get the source from the same Controller and Method. Code: $routes->get('{locale}/about-us', 'Helloworld::about_us'); Everything is clear.
Sorry, but Codeigniter have a specific folder called language for translate multilangual sites. Why i should use a mySQL table for to do this?
![]()
It depends on what you are trying to accomplish. For my blog, I have a column in the article table for the language it is written in. I have only one controller that is used by all languages but it fetch only the articles in the language matching the locale defined in the url. I also have a column for the slug because I didn’t want to define a route for each article in every language. In this particular case, I don’t need a different controller for EN and for FR.
For the list of blog posts, the urls will look like this: Code: /en/blog And for the blog posts, the urls will look like this: Code: /en/blog/some-article-in-english (04-30-2021, 07:01 AM)eleumas Wrote: Sorry, but Codeigniter have a specific folder called language for translate multilangual sites. Why i should use a mySQL table for to do this? Well, If you think like that, it looks you have a long way to produce a larger scale project. Language folder is for texts, not for your algorithms. In order to set the correct relational structure and algorithm you will need a very basic and solid branch to grasp, to connect/join everything in a clear way. So, a language column on your table will save your life and will make everything easier. + On your that ,mutual, product page, let's imagine a title of a part with if: PHP Code: <?php if($lang == 'en'){ but with language file you can only write : PHP Code: <?php echo lang('MyLangFile.catPartTitle');?> that's all and clear again. cordiali saluti ![]()
I have a simple site without blog or anything.
I would like only translate the text and i would like have an example how to use localization in Codeigniter 4 because i have some issue how i have specificed in my first post. I know if the app is more complex i have to use a database and not a language file, but for example for the navbar items or others parts i can use a language file, no needed a database. Thanks for help me.
Read this may help you to understand what were talking about.
Multilanguage Database Design in MySQL What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
|
Welcome Guest, Not a member yet? Register Sign In |