Multilingual Menu stored in the database
- Armin Schmidtke
- Member | 20
Hi folks,
what is your preferred way / best practices to store a multilingual menu in a
database with nette?
I'm trying to figure out a simple way for multilingual support and future translations, if there will be added any additional language.
Thanks for any advice!
- Armin Schmidtke
- Member | 20
I'm looking for a good starting point on how to achieve a clean multilingual menu dynamically from the database. My problem, I don't know exactly how to start. So this was meant more global if anybody has some best practise, an example link to an app on github or any advice?
- Tomáš Votruba
- Moderator | 1114
I see.
After I made my own “Menu builder”, I've decided to drop it and to use something more established and standardized. Worth it :)
I meant to say I have good experience with KnpMenu package.
Some year ago made also an repository with implementation to Nette. Check it for inspiration.
There are 2 good starting points:
- EventSubscriber that adds item's to the menu – this the place for getting items from database
- test, that validates this
Last edited by Tomáš Votruba (2016-06-05 11:20)
- Armin Schmidtke
- Member | 20
Cool, this package looks good. Thanks a lot for taking your time and helping me out! This already solved another problem I had and I was researching for.
But even with this package I have still no clue on how to translate my menu.
Maybe my preview posts didn't make much sense so let me try to explain it more
specifically.
I'm writing a Blog where my Categories are the main menu. The app uses
Kdyby/Translation which works great. But how can I store the translations of
the menu in the database?
- Armin Schmidtke
- Member | 20
just came up with something this:
Table "categories":
----------------
id : int
Table "category_translations"
---------------------------
category_id : int
language : varchar
name : varchar
<any other localized data>
I guess my question is a bit off topic because it isn't really related to nette but more on how I design the database. Sorry for that.
- Tomáš Votruba
- Moderator | 1114
Well, Kdyby\Translation is rather for string translations, not dynamic ones. There had been some PR for database translations, but I don't recall it was finished.
But I have some good news too! If you use Doctrine, the solution would be simple.
For translated entities you can use:
Then decorate your entities with traits as in following example.
- Armin Schmidtke
- Member | 20
No, I'm not using Doctrine.. Anyway, thanks a lot for your help!! I'll think about it. It's a small project (a Blog where I want to post articles in multiple languages) so I may stick to something like I posted earlier. But your solution is definitely worth to try out on the next project.
I just need some time to get comfortable with doctrine (:
- Tomáš Votruba
- Moderator | 1114
I understand that, Doctrine needs time :)
I think I can make learning Doctrine easier for you.
There is a nice list with selection of top Doctrine resources, from slides, videos or articles to blog series. Mostly up to date and from recent years.
Check it out, when you need it – Awesome Doctrine.
- obertuckerz112
- Member | 3
I'm trying to determine where the menu names for our Joomla site are stored. For instance, we have one of the pre-installed menus, called “mainmenu”, but I'm not sure where “mainmenu”, the name of the menu itself, is stored.