import { myAuthRequired } from "@utils/app";
-import getUserPrimaryLanguage from "@utils/app/user-primary-language";
+import getUserInterfaceLangId from "@utils/app/user-interface-language";
import { capitalizeFirstLetter } from "@utils/helpers";
import { Component } from "inferno";
import { T } from "inferno-i18next-dess";
: undefined
: undefined;
- const userPrimaryLanguage = getUserPrimaryLanguage(
- UserService?.Instance?.myUserInfo
- );
+ const userInterfaceLangId = getUserInterfaceLangId({
+ myUserInfo: UserService.Instance.myUserInfo,
+ allLanguages: this.props.allLanguages,
+ });
return (
<div
{UserService.Instance.myUserInfo ? (
<MarkdownTextArea
initialContent={initialContent}
- initialLanguageId={userPrimaryLanguage}
+ initialLanguageId={userInterfaceLangId}
showLanguage
buttonTitle={this.buttonTitle}
finished={this.props.finished}
myAuth,
myAuthRequired,
} from "@utils/app";
-import getUserPrimaryLanguage from "@utils/app/user-primary-language";
+import getUserInterfaceLangId from "@utils/app/user-interface-language";
import {
capitalizeFirstLetter,
debounce,
}
render() {
- const userPrimaryLanguage = getUserPrimaryLanguage(
- UserService?.Instance?.myUserInfo
- );
-
const url = this.state.form.url;
+ const userInterfaceLangId = getUserInterfaceLangId({
+ myUserInfo: UserService.Instance.myUserInfo,
+ allLanguages: this.props.allLanguages,
+ });
+
return (
<form className="post-form" onSubmit={linkEvent(this, handlePostSubmit)}>
<NavigationPrompt
</div>
<LanguageSelect
allLanguages={this.props.allLanguages}
- selectedLanguageIds={[userPrimaryLanguage]}
+ selectedLanguageIds={[userInterfaceLangId]}
siteLanguages={this.props.siteLanguages}
multiple={false}
onChange={this.handleLanguageChange}
import siteBannerCss from "./site-banner-css";
import updateCommunityBlock from "./update-community-block";
import updatePersonBlock from "./update-person-block";
-import getUserPrimaryLanguage from "./user-primary-language";
+import getUserInterfaceLangId from "./user-interface-language";
export {
buildCommentsTree,
getIdFromProps,
getRecipientIdFromProps,
getUpdatedSearchId,
- getUserPrimaryLanguage,
+ getUserInterfaceLangId,
initializeSite,
insertCommentIntoTree,
isAuthPath,
--- /dev/null
+import { Language, MyUserInfo } from "lemmy-js-client";
+import { I18NextService } from "../../services/I18NextService";
+
+export default function getUserInterfaceLanguageId({
+ myUserInfo,
+ allLanguages,
+}: {
+ myUserInfo: MyUserInfo;
+ 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
+ return userLang.id || 0;
+}
+++ /dev/null
-import { UserService } from "../../services";
-
-export default function getUserPrimaryLanguage(
- myUserInfo = UserService.Instance.myUserInfo
-): number {
- // Get first language in discussion languages array that isn't equal to "0",
- // which is the language selection "Undetermined"
- return myUserInfo?.discussion_languages.find(lang => lang !== 0) || 0;
-}