Skip to content

Commit

Permalink
fix(issue-56): load language
Browse files Browse the repository at this point in the history
  • Loading branch information
cesarwbr committed Mar 25, 2024
1 parent 20a058c commit d1059bb
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-input-emoji",
"version": "5.6.6",
"version": "5.6.7",
"description": "A React input with an option to add an emoji with language support.",
"homepage": "https://cesarwbr.github.io/react-input-emoji/",
"author": "cesarwbr",
Expand Down
2 changes: 2 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ export default {
file: pkg.main,
format: 'cjs',
sourcemap: true,
inlineDynamicImports: true,
},
{
file: pkg.module,
format: 'es',
sourcemap: true,
inlineDynamicImports: true,
},
],
plugins: [
Expand Down
31 changes: 26 additions & 5 deletions src/components/emoji-picker.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// vendors
import React, { memo, useMemo } from "react";
import React, { memo, useEffect, useMemo, useState } from "react";
import Picker from "@emoji-mart/react";

/**
Expand Down Expand Up @@ -42,13 +42,34 @@ function EmojiPicker(props) {
return categoryies;
}, [disableRecent]);

const i18n = useMemo(() => {
const [i18n, setI18n] = useState(undefined);

useEffect(() => {
if (!language) {
return undefined
// @ts-ignore
import(`@emoji-mart/data/i18n/en.json`)
.then(translations => {
setI18n(translations);
})
.catch(error => {
console.error("Failed to load translations:", error);
});
return;
}

return require(`@emoji-mart/data/i18n/${language ?? 'en'}.json`)
}, [language])
// @ts-ignore
import(`@emoji-mart/data/i18n/${language}.json`)
.then(translations => {
setI18n(translations);
})
.catch(error => {
console.error("Failed to load translations:", error);
});
}, [language]);

if (!i18n) {
return null;
}

return (
<Picker
Expand Down

0 comments on commit d1059bb

Please sign in to comment.