diff --git a/src/shared/components/comment/comment-form.tsx b/src/shared/components/comment/comment-form.tsx index 294960a8..c9937c62 100644 --- a/src/shared/components/comment/comment-form.tsx +++ b/src/shared/components/comment/comment-form.tsx @@ -1,4 +1,5 @@ import { myAuthRequired } from "@utils/app"; +import getUserInterfaceLangId from "@utils/app/user-interface-language"; import { capitalizeFirstLetter } from "@utils/helpers"; import { Component } from "inferno"; import { T } from "inferno-i18next-dess"; @@ -40,6 +41,8 @@ export class CommentForm extends Component { : undefined : undefined; + const userInterfaceLangId = getUserInterfaceLangId(this.props.allLanguages); + return (
{ {UserService.Instance.myUserInfo ? ( { return this.props.iconVersion ? ( this.selectBtn ) : ( -
+
diff --git a/src/shared/utils/app/index.ts b/src/shared/utils/app/index.ts index 9993ac72..f98357d7 100644 --- a/src/shared/utils/app/index.ts +++ b/src/shared/utils/app/index.ts @@ -53,6 +53,7 @@ import showScores from "./show-scores"; import siteBannerCss from "./site-banner-css"; import updateCommunityBlock from "./update-community-block"; import updatePersonBlock from "./update-person-block"; +import getUserInterfaceLangId from "./user-interface-language"; export { buildCommentsTree, @@ -87,6 +88,7 @@ export { getIdFromProps, getRecipientIdFromProps, getUpdatedSearchId, + getUserInterfaceLangId, initializeSite, insertCommentIntoTree, isAuthPath, diff --git a/src/shared/utils/app/user-interface-language.ts b/src/shared/utils/app/user-interface-language.ts new file mode 100644 index 00000000..ff2e4390 --- /dev/null +++ b/src/shared/utils/app/user-interface-language.ts @@ -0,0 +1,18 @@ +import { Language } from "lemmy-js-client"; +import { I18NextService } from "../../services/I18NextService"; + +export default function getUserInterfaceLangId( + allLanguages: Language[] +): number { + // Get the string of the browser- or user-defined language, like en-US + const i18nLang = I18NextService.i18n.language; + + // Find the Language object with a code that matches the initial characters of + // this string + const userLang = allLanguages.find(lang => { + return i18nLang.indexOf(lang.code) === 0; + }); + + // Return the ID of that language object, or "0" for Undetermined + return userLang?.id || 0; +}