nuxt-monaco-editor icon indicating copy to clipboard operation
nuxt-monaco-editor copied to clipboard

Dynamically change locale

Open starnayuta opened this issue 1 year ago • 3 comments

How to change the locale dynamically? The locale should change dynamically when the user changes the locale like from en to ja.

https://e-chan1007.github.io/nuxt-monaco-editor/guide/configuration#locale

starnayuta avatar Sep 10 '23 16:09 starnayuta

<template>
  <MonacoEditor
    style="height: 100px"
    v-model="value"
    :lang="lang"
    ref="editorRef"
  />
  <button @click="toggleLanguage">goggle language</button>
</template>

<script setup>
import * as monacro from "monaco-editor";
const value = ref("");
const lang = ref("html");
const editorRef = ref(null);
const toggleLanguage = () => {
  const editor = toRaw(editorRef.value.$editor);
  monacro.editor.setModelLanguage(editor.getModel(), "javascript");
};
</script>

This is a demo that switches languages, I hope it can help you

cc-hearts avatar Oct 10 '23 09:10 cc-hearts

@cc-hearts

Thanks for your comment.

The issue is not the language of the editor (e.g. javascript, css) but the locale (e.g. en, ja). https://e-chan1007.github.io/nuxt-monaco-editor/guide/configuration#locale

For example, if a user changes the locale from en to ja, we cannot tell nuxt-monaco-editor to change the locale.

I edited my comment to make the meaning clearer.

Thanks.

starnayuta avatar Oct 10 '23 16:10 starnayuta

As far as I have tried, it is not able to change the locale dynamically due to the specification of monaco-editor. I will continue to find an alternative way to implement this.

e-chan1007 avatar Dec 03 '23 06:12 e-chan1007