"use strict";(self.webpackChunkdashy=self.webpackChunkdashy||[]).push([[118],{3905:function(e,t,n){n.d(t,{Zo:function(){return u},kt:function(){return g}});var a=n(7294);function i(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function o(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,a)}return n}function r(e){for(var t=1;t=0||(i[n]=e[n]);return i}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(a=0;a=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}var s=a.createContext({}),p=function(e){var t=a.useContext(s),n=t;return e&&(n="function"==typeof e?e(t):r(r({},t),e)),n},u=function(e){var t=p(e.components);return a.createElement(s.Provider,{value:t},e.children)},d={inlineCode:"code",wrapper:function(e){var t=e.children;return a.createElement(a.Fragment,{},t)}},c=a.forwardRef((function(e,t){var n=e.components,i=e.mdxType,o=e.originalType,s=e.parentName,u=l(e,["components","mdxType","originalType","parentName"]),c=p(n),g=i,h=c["".concat(s,".").concat(g)]||c[g]||d[g]||o;return n?a.createElement(h,r(r({ref:t},u),{},{components:n})):a.createElement(h,r({ref:t},u))}));function g(e,t){var n=arguments,i=t&&t.mdxType;if("string"==typeof e||i){var o=n.length,r=new Array(o);r[0]=c;var l={};for(var s in t)hasOwnProperty.call(t,s)&&(l[s]=t[s]);l.originalType=e,l.mdxType="string"==typeof e?e:i,r[1]=l;for(var p=2;p{{ $t('my-widget.awesome-text') }}

\n")),(0,o.kt)("p",null,"Note that the ",(0,o.kt)("inlineCode",{parentName:"p"},"{{ }}")," just tells Vue that this is JavaScript/ dynamic.\nThis will render: ",(0,o.kt)("inlineCode",{parentName:"p"},"

I am some text, that will be seen by the user

")),(0,o.kt)("p",null,"If you need to display text programmatically, from within the components JavaScript (e.g. in a toast popup), then use ",(0,o.kt)("inlineCode",{parentName:"p"},"this.$t"),".\nFor example: ",(0,o.kt)("inlineCode",{parentName:"p"},"alert(this.$t('my-widget.awesome-text'))"),"."),(0,o.kt)("p",null,"You may also need to pass a variable to be displayed within a translation. Vue I18n supports ",(0,o.kt)("a",{parentName:"p",href:"https://vue-i18n.intlify.dev/guide/essentials/syntax.html#interpolations"},"Interpolations")," using mustache-like syntax."),(0,o.kt)("p",null,"For example, you would set your translation to:"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-json"},'{\n "welcome-message": "Hello {name}!"\n}\n')),(0,o.kt)("p",null,"And then pass that variable (",(0,o.kt)("inlineCode",{parentName:"p"},"name"),") within a JSON object as the second parameter on ",(0,o.kt)("inlineCode",{parentName:"p"},"$t"),", like:"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-javascript"},"$t('welcome-message', { name: 'Alicia' })\n")),(0,o.kt)("p",null,"Which will render:"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-text"},"Hello Alicia!\n")),(0,o.kt)("p",null,"There are many other advanced features, including Pluralization, Datetime & Number Formatting, Message Support and more, all of which are outlined in the ",(0,o.kt)("a",{parentName:"p",href:"https://vue-i18n.intlify.dev/guide/"},"Vue-i18n Docs"),"."),(0,o.kt)("h4",{id:"basic-example"},"Basic Example"),(0,o.kt)("p",null,"Using the search bar as an example, this would look something like:"),(0,o.kt)("p",null,"In ",(0,o.kt)("a",{parentName:"p",href:"https://github.com/Lissy93/dashy/blob/master/src/components/Settings/SearchBar.vue"},(0,o.kt)("inlineCode",{parentName:"a"},"./src/components/Settings/SearchBar.vue")),":"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-vue"},'\n')),(0,o.kt)("p",null,"Then in ",(0,o.kt)("a",{parentName:"p",href:"https://github.com/Lissy93/dashy/blob/master/src/assets/locales/en.json"},(0,o.kt)("inlineCode",{parentName:"a"},"./src/assets/locales/en.json")),":"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-json"},'{\n"search": {\n "search-label": "Search",\n "search-placeholder": "Start typing to filter",\n },\n ...\n}\n')))}c.isMDXComponent=!0}}]);