0

sorry, I am not very experienced with nodejs I see the following error below.

ERROR in ./src/ui/EditorToolbarConfig.js
Module build failed (from ./node_modules/babel-loader/lib/index.js):
SyntaxError: /Applications/MAMP/htdocs/prosemirror12/src/ui/EditorToolbarConfig.js:

Unexpected token (166:13)

  164 |     '[image] Insert image': [
  165 |       {
> 166 |         lang('Insert image by URL'): IMAGE_FROM_URL,

I have written a separate js file i18.js:

let lang_list = {}
lang_list['en'] = {'Insert Table...': 'Insert Table...',
                  'Fill Color...': 'Fill Color...',}
lang_list['zh'] = {'Insert Table...': 'Insert Table...',
                  'Fill Color...': 'Fill Color...',
                  'Border Color....': 'Border Color....'}


export default function Lang(text) {
    if (text in lang_list['zh']) {
      return lang_list['zh'][text]
    }

    return text
}

and I wish to load this file in here EditorToolbarConfig.js:

import Lang from './i18n';
export const COMMAND_GROUPS = [
  {
   Lang( 'Insert image by URL'): FontTypeCommandMenuButton,
  },
  {
   Lang( '[format_size] Text Size'): FontSizeCommandMenuButton,
  }]

For some reason, I see the error above.

Thanks!

0

1 Answer 1

1

You should use brackets for dynamic keys.

export const COMMAND_GROUPS = [
  {
    [Lang("Insert image by URL")]: FontTypeCommandMenuButton,
  },
  {
    [Lang("[format_size] Text Size")]: FontSizeCommandMenuButton,
  },
];
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much! This simple syntax error has driven me crazy...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.