Skip to content

Commit

Permalink
finish of simple i18n
Browse files Browse the repository at this point in the history
  • Loading branch information
joaoeudes7 committed May 16, 2020
1 parent 1f0ff75 commit 1c27519
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 23 deletions.
7 changes: 1 addition & 6 deletions src/VEmojiPicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
:current="currentCategory"
@select="changeCategory"
/>
<InputSearch v-if="showSearch" @update="onSearch" :placeholder="labelSearch" />
<InputSearch v-if="showSearch" @update="onSearch" />
<EmojiList
:data="mapEmojis"
:category="currentCategory"
Expand Down Expand Up @@ -57,7 +57,6 @@ export default class VEmojiPicker extends Vue {
@Prop({ default: "Peoples" }) initialCategory!: string;
@Prop({ default: () => [] as ICategory[] }) exceptCategories!: ICategory[];
@Prop({ default: () => [] as Emoji[] }) exceptEmojis!: IEmoji[];
@Prop({}) lang!: string;
@Prop({}) i18n!: Object;
mapEmojis: MapEmojis = {};
Expand All @@ -76,10 +75,6 @@ export default class VEmojiPicker extends Vue {
this.restoreFrequentlyEmojis();
// Configure i18n
if (this.lang) {
locale.use(this.lang);
}
if (this.i18n) {
locale.i18n(this.i18n);
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/InputSearch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<script lang="ts">
import { Component, Prop, Vue, Watch } from "vue-property-decorator";
import { st } from "@/locale";
import { t } from "@/locale";
const timemout = 500;
let listenInput: number;
Expand All @@ -25,7 +25,7 @@ export default class InputSearch extends Vue {
}
get placeholder() {
return st("search");
return t("search");
}
}
</script>
Expand Down
3 changes: 0 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,11 @@ import { emojisDefault } from './utils/emojis';
import locale from './locale';

const defaultOptions = {
locale: 'en-UK',
i18n: {}
}

const VEmojiPicker: PluginObject<_VEmojiPicker> = {
install: (Vue, opts: any = defaultOptions) => {

locale.use(opts.locale);
locale.i18n(opts.i18n);

Vue.component(_VEmojiPicker.name, _VEmojiPicker);
Expand Down
15 changes: 5 additions & 10 deletions src/locale/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
import langDefault from './lang/enUK';

let lang = {};

export const i18n = (translations: Object) => {
lang = { ...lang, ...translations }
}

export const use = (initials: string) => {
if (initials.trim().length) {
const nLang = require(`./lang/${initials}`).default
i18n(nLang)
}
lang = { ...langDefault, ...translations }
}

// Sample parse translation
export const st = (term: string) => {
export const t = (term: string) => {
const properties = term.split(".")
let text = lang

Expand All @@ -23,4 +18,4 @@ export const st = (term: string) => {
return text
}

export default { use, i18n, t: st }
export default { i18n, t }
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions src/models/Category.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { st } from '@/locale';
import { t } from '@/locale';

export interface ICategory {
name: string;
Expand All @@ -12,6 +12,6 @@ export class Category implements ICategory {
) { }

get label() {
return st(`categories.${this.name}`)
return t(`categories.${this.name}`)
}
}

0 comments on commit 1c27519

Please sign in to comment.