Get 2024 Templates Mega Bundle!14 Bootstrap, Vue & React Templates + 3 Vector Sets
Get for 99$

Use Translations in config menu files


Hi,
I would need support on an issue regarding menu configuration files.

In the 'config/global' folder is the menu.php file where clearly the array for rendering the actual menu is to be configured, I would need to make the names of the various menu items translatable e.g. 'Products', 'Customers' etc..

if I try to use the Laravel methods so __("Products") or trans("Products") the software goes into exception because the class 'translator' doesn't exist.
'ReflectionException > BindingResolutionException: Target class [translator] does not exist.'

Clearly this would happen in any file that is present in 'config/', how can I solve it?


Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(

Replies (3)


Hi Nunzio,

To enable translation for the menu title, please find file in the app/Core/Menu.php, you can make the following changes:

1. Look for the function _generateItemLinkTitle

2. Find the line that has echo $title;

3. Replace it with

echo __($title);


4. After that, you can use the translation key for "title" in the menu.php config. For example:


"title" => "Products"


When the menu is rendered, the title will be executed using the code __('Products'), which enables translation for the menu title.


Thanks



Hi, the demo9 I'm using doesn't provide the 'title' property, because if I used it it would mess up the layout, so I made the change in the 'Core/Adampters/Menu' file by going to do this check

if (array_key_exists("attributes", $value)) {
$value["attributes"]["link"]["title"] = "<h6>" . __($value["attributes"]["link"]["title"]) . "</h6>";
}

Is this an equally valid solution?



Hi Nunzio,

Yes, the solution you implemented in the 'Core/Adapters/Menu' file seems to be valid. By adding the check to ensure the 'attributes' key exists and modifying the 'title' property, you are customizing the menu rendering to include the HTML markup for the 'title' element.

Thanks


Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(