Issue #2718💬 AnsweredOpened April 17, 2020by Lerdouille0 reactions

Can't use i18n

快速解答by pouyamiralayi

@Lerdouille your issue is not related to grapesjs, you have to reference your locale objects somehow which i suggest using global variables for them, and to import them, is basically a matter of including their related scripts inside your html. Cheers!

Read full answer below ↓

Question

代码片段TEXT
Hi again @artf ,
you close my previous ticket but i don't succeed to reopen it

i saw the documentation and the part reguarding i18n but i didn't succed to use it.
In your documentation, you use some import function, basically my code is pretty simpler and without import, like this :

<html>
<body>
<link rel="stylesheet" href="grapesjs/css/grapes.min.css">
<script src="grapesjs/grapes.js"></script>
<div id="gjs">
<h1>Hello World Component!</h1>
</div>
<script type="text/javascript">
var editor = grapesjs.init({
showOffsets: 1,
noticeOnUnload: 0,
container: '#gjs',
height: '100%',
width: 'auto',
fromElement: true,
showDevices: 0,
storageManager: { autoload: 0 },
});
</script>
</body>
</html>

I managed too implement some plugins and configure the design of the editor, but i'm stucked with this i18n issue...

Could you please tell me what i'm doing wrong ? for the record i'm not in a Node environnement

I precise that i apparently my project is for now composed with only 3 files, the grapesjs.js, grapes.css and my HTML file. When i download your project on github, there are a few folders (and specially on named /src where i can find the locales files), but the plugin does not need them to work, is it normal ?

Regards and thank you again for the support :)

Answers (3)

pouyamiralayiApril 18, 2020

@Lerdouille your issue is not related to grapesjs, you have to reference your locale objects somehow which i suggest using global variables for them, and to import them, is basically a matter of including their related scripts inside your html. Cheers!

artfApril 20, 2020

Current code of locale files are optimized only for importing them via import, if you want to improve that PR are welcome

you close my previous ticket but i don't succeed to reopen it

There is no need to keep questions open if there is a need to reply I'll do it, so please, next time avoid opening other duplicates

LerdouilleApril 20, 2020

Thank you for your answers. I do succeed to display the good translation by tweaking the grapes.js.

To do that, i had to copy/paste the part

**/ "./src/i18n/locale/en.js": /!!
!
./src/i18n/locale/en.js ! *
/ /*! exports provided: default */

and replace all translation by another langage.

Then, i had to declare the variables in the part : "./src/i18n/config.js" with this (for French translation in my code) : /* harmony import / var locale_fr__WEBPACK_IMPORTED_MODULE_0_ = webpack_require(/! ./locale/fr */ "./src/i18n/locale/fr.js");

and update the "message" variable below by : messages: { en: locale_en__WEBPACK_IMPORTED_MODULE_0_["default"], fr: locale_fr__WEBPACK_IMPORTED_MODULE_0_["default"] }

Related Questions and Answers

Continue research with similar issue discussions.

Paid Plugins That Match This Issue

Curated by issue keywords and label relevance to help you ship faster.

View all plugins

Loading paid plugin recommendations...

Free option

Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.

Browse free plugins →
Premium option

Premium plugins ship with support, regular updates, and production-ready features — save days of integration work.

Browse premium plugins →

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.