Skip to content

Commit

Permalink
Merge pull request #37 from jxpeng98/pluggin-does-not-appear-on-mac
Browse files Browse the repository at this point in the history
fix: obsidian language not set in English, Chinese and Japanese
  • Loading branch information
jxpeng98 authored Sep 19, 2024
2 parents 00411e9 + 8bd8346 commit 48566ec
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 29 deletions.
42 changes: 37 additions & 5 deletions src/lang/I18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,42 @@ export const I18n: {[key: string]:any} = {
ja,
};

export const I18nConfig = (lang: string): any => {
return I18n[lang];
};
class I18nManager {
private currentLanguage: string;

constructor() {
this.currentLanguage = this.detectLanguage();
}

// return the language to use
private detectLanguage(): string {
const storedLanguage = window.localStorage.getItem("language");
if (storedLanguage && this.isLanguageSupported(storedLanguage)) {
console.log(`Using stored language: ${storedLanguage}`);
return storedLanguage;
}

const browserLanguage = window.navigator.language.split("-")[0];
if (this.isLanguageSupported(browserLanguage)) {
console.log(`Using browser language: ${browserLanguage}`);
return browserLanguage;
}

// Default to English if no match is found
console.log("Using default language: en");
return "en";
}

private isLanguageSupported(lang: string): boolean {
return Object.prototype.hasOwnProperty.call(I18n, lang);
}

// Get the i18n configuration for the current language
public getConfig(): any {
return I18n[this.currentLanguage];
}
}

const storedLanguage = window.localStorage.getItem("language");
export const i18nManager = new I18nManager();

export const i18nConfig = I18n[storedLanguage || window.navigator.language.split('-')[0] || "en"];
export const i18nConfig = i18nManager.getConfig();
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default class ObsidianSyncNotionPlugin extends Plugin {

addIcons();
// This creates an icon in the left ribbon.
const ribbonIconEl = this.addRibbonIcon(
this.addRibbonIcon(
"notion-logo",
i18nConfig.ribbonIcon,
async (evt: MouseEvent) => {
Expand Down
23 changes: 0 additions & 23 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -460,14 +460,6 @@ commander@^8.3.0:
resolved "https://registry.yarnpkg.com/commander/-/commander-8.3.0.tgz#4837ea1b2da67b9c616a67afbb0fafee567bca66"
integrity sha512-OkTL9umf+He2DZkUq8f8J9of7yL6RJKI24dVITBmNfZBmri9zYZQrKkuXiKhyfPSu8tUhnVBB1iKXevvnlR4Ww==

cors@^2.8.5:
version "2.8.5"
resolved "https://registry.yarnpkg.com/cors/-/cors-2.8.5.tgz#eac11da51592dd86b9f06f6e7ac293b3df875d29"
integrity sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==
dependencies:
object-assign "^4"
vary "^1"

data-uri-to-buffer@^4.0.0:
version "4.0.1"
resolved "https://registry.yarnpkg.com/data-uri-to-buffer/-/data-uri-to-buffer-4.0.1.tgz#d8feb2b2881e6a4f58c2e08acfd0e2834e26222e"
Expand Down Expand Up @@ -722,11 +714,6 @@ katex@^0.16.0:
dependencies:
commander "^8.3.0"

ky@^1.7.2:
version "1.7.2"
resolved "https://registry.yarnpkg.com/ky/-/ky-1.7.2.tgz#b97d9b997ba51ff1e152f0815d3d27b86513eb1c"
integrity sha512-OzIvbHKKDpi60TnF9t7UUVAF1B4mcqc02z5PIvrm08Wyb+yOcz63GRvEuVxNT18a9E1SrNouhB4W2NNLeD7Ykg==

longest-streak@^2.0.0:
version "2.0.4"
resolved "https://registry.yarnpkg.com/longest-streak/-/longest-streak-2.0.4.tgz#b8599957da5b5dab64dee3fe316fa774597d90e4"
Expand Down Expand Up @@ -1228,11 +1215,6 @@ node-fetch@^3.3.2:
fetch-blob "^3.1.4"
formdata-polyfill "^4.0.10"

object-assign@^4:
version "4.1.1"
resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863"
integrity sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==

obsidian@^1.6.6:
version "1.6.6"
resolved "https://registry.yarnpkg.com/obsidian/-/obsidian-1.6.6.tgz#d45c4021c291765e1b77ed4a1c645e562ff6e77f"
Expand Down Expand Up @@ -1459,11 +1441,6 @@ unist-util-visit@^5.0.0:
unist-util-is "^6.0.0"
unist-util-visit-parents "^6.0.0"

vary@^1:
version "1.1.2"
resolved "https://registry.yarnpkg.com/vary/-/vary-1.1.2.tgz#2299f02c6ded30d4a5961b0b9f74524a18f634fc"
integrity sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==

vfile-message@^2.0.0:
version "2.0.4"
resolved "https://registry.yarnpkg.com/vfile-message/-/vfile-message-2.0.4.tgz#5b43b88171d409eae58477d13f23dd41d52c371a"
Expand Down

0 comments on commit 48566ec

Please sign in to comment.