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

Translation


import { useI18n } from "vue-i18n";
const i18n = useI18n()
how I can use it in folder router in index.ts file to translate for example :
pageTitle: "title",
breadcrumbs: ["bread"],

I have tried a lot but to no avail

Metronic demo 8 version 8.1.7
node v18.12.0
npm 9.1.2

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  :(

Replies (27)


Hi Hosam Nouri,

You can use here a different approach, instead of translating these properties inside index.ts you can set the keys and then inside PageTitle.vue you can display translation values.

Here is an example.

import { useI18n } from "vue-i18n";


const { t } = useI18n();


const pageTitle = computed(() => {
return t(route.meta.pageTitle as string);
});


Regards,
Lauris Stepanovs,
Keenthemes Support Team



Sorry but not working
I will explain to you
In my route file i have like this :

{
path: "/iphone",
name: "iphone",
component: () => import("@/views/device/iphones/iphone.vue"),
meta: {
pageTitle: "iphone",
breadcrumbs: ["samsung"],
},
},

What I want is a translation value of pageTitle Its value here is equal " iphone "
so how I can do this
Please explain to me



Hi Hosam Nouri,

You can translate this value using t function which you get form useI18n().


import { useI18n } from "vue-i18n";
const { t } = useI18n();


As a parameter t function expects key and returns value by current language.

Did you add your key into file src/core/plugins/i18n.ts language configuration?

Regards,
Lauris Stepanovs,
Keenthemes Support Team



Yes I did ,
I added the key into i18n.ts , not working
I useed this way in my all components and its working very well ,
but the issue when i want use it in route.ts
{
path: "/iphone",
name: "iphone",
component: () => import("@/views/device/iphones/iphone.vue"),
meta: {
pageTitle: "iphone",
breadcrumbs: ["samsung"],
},
},

What I want is a translation value of pageTitle Its value here is equal " iphone "



Hi Hosam Nouri,

If you want to translate these values inside index.ts you can refer to this comment.
https://github.com/intlify/vue-i18n-next/discussions/613#discussioncomment-2265983

I would suggest you instead of translating values inside the router file translate them inside components whenever you are using the page title.

Regards,
Lauris Stepanovs,
Keenthemes Support Team



How I can translate them inside components ,
How can I access the router file from the component ?



Hi Hosam Nouri,

You can use the code from my first comment.

import { useI18n } from "vue-i18n";
const { t } = useI18n();

const pageTitle = computed(() => {
return t(route.meta.pageTitle as string);
});


Then just display the output of pageTitle in your markup.

Or you can return t function and then use it inside a markup directly.


<div ...>{t(pageTitle)}</div>


Regards,
Lauris Stepanovs,
Keenthemes Support Team



The thing I want is in the pageTitle.vue

const pageTitle = computed(() => {
return t(route.meta.pageTitle as string);
});

const breadcrumbs = computed(() => {
return t(route.meta.breadcrumbs as string);
});


Thanks ...



Hi Hosam Nouri,

Glad to hear that it worked for you. All the best with your project!

Regards,
Lauris Stepanovs,
Keenthemes Support Team



const pageTitle = computed(() => {
return t(route.meta.pageTitle as string);
});

const breadcrumbs = computed(() => {
return t(route.meta.breadcrumbs as string);
});

iq test



Unlock the potential of your business with our expert SEO services. Drive traffic, boost rankings, and dominate search engine results today!



Visit Declare to check out the newest selection of beautiful new dresses. Discover your ideal dress for every event with our selection of stylish party dresses. Shop now and step up your fashion game with Declare's trendy designs.



Jazmin offers a large number of ready to wear for girls and women in Pakistan at low prices. We provide the highest quality fabric in various colors and styles Grab your favorite dresses online at Jazmin.



Browse a gorgeous variety of chiffon dresses perfect for every event. Find the ideal chiffon garment to casually improve your style, whether it's a stylish evening dress or a casual day dress. Get classic style and a hint of charm today.



Figure the most affordable Lego and safe for kids building blocks toys in Pakistan. The Entertainer has a large selection of Lego and block toys to explore.



Browse our online store for a wide range of Pakistani wedding dresses. Find the perfect ensemble for your special day. Shop now.



Using our selection of casual shirts for men, you can up your style score! Discover new styles and traditional favorites at our online store. Get quality shirts right now to easily update your style.



Discover the latest Trousers Design at ECS. Our collection features the best styles and colors to suit any occasion. Shop now and enjoy our great offers on women's trousers.



Discover the latest collection ofwomen dress design by Nishat Linen. Explore a wide range of stunning designs and styles perfect for any occasion in Pakistan. Shop now and find your perfect dress!



Mohagni offers the best ladies trouser design online in Pakistan. With an extensive variety to choose from and speedy delivery services, Mohagni emerges as the ultimate destination to meet all your online shopping requirements.



Discover the new latest dress designs for any event. Find the perfect look by keeping up with the latest trends in fashion. Whether it is casual or formal, our collection of new dress styles will keep you looking stylish and confident. Check it out right now!



Welcome to Servis Online Official Store. Join us and get the best selection of shoes for men and other products. Buy shoes for men online in Pakistan at reasonable Prices from Servis.



Discover the secret to youthful and radiant skin with HA Serum by Her Beauty. Transform your skincare routine with our highly effective and nourishing HA serum.



Discover the latest collection of Embroidered chiffon dresses. Perfect for any occasion, these elegant and stylish dresses will make you stand out from the crowd. Stay fashionable with Ramsha.



Get ready for your Umrah journey with the perfect Ihram. Find a comfortable, high-quality Ihram for Umrah to ensure a smooth and sacred pilgrimage experience. Shop now for your essential Umrah attire.



Discover a wide range of niacinamide serum, including The Ordinary Serum and The Ordinary Niacinamide serum, at Chahyay. Shop now for all your skincare needs.



Ensure your future prospects shine bright with our meticulous degree certificate attestation in UAE, guaranteeing credibility across borders.


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  :(