Sign in to follow this  
ekoozu

Loading i18next on client-side

Recommended Posts

Hey,

 

I'm trying to load i18next on client-side but it doesn't work, here is what i am doing:

 

I downloaded the i18next script: https://unpkg.com/i18next/dist/umd/i18next.js

Put in client_packages

And trying to load like that:

const i18next = require('./plugins/i18next');
 
// languages
import en from 'lang/en';
 
i18next.init({
lng: 'en',
resources: {
en,
}
});

But it says i18next.init is not a function, i tried doing that with a simple node script and it worked, i know that clientside doesn't run on node, but shouldn't this work?

 

Appreciate any help, thanks.

Share this post


Link to post
Share on other sites
Posted (edited)

Hey, thanks for the reply.

 

Appending .js doesn't seem to change anything, the file seems to be importing, because if i change the path it says `Error: could not locate file`.

But for some reason on rage it doesn't seem to import the data from the file, i made this script to test (node index.js) and it works.

const i18next = require('./i18next');
 
i18next.init({
lng: 'en',
debug: false,
resources: {
en: {
translation: {
"key": "hello world"
}
}
}
}, function(err, t) {
console.log(i18next.t('key'));
});

This is the error RAGE returns:

d5BXDDy.jpg

Maybe the way i18next is exported doesn't work on rage? Is there a way to make it work?

 

Thanks.

Edited by ekoozu

Share this post


Link to post
Share on other sites
Posted (edited)

I know, this package doesn't need node specifically.

 

EDIT: Figured out how to do it, if anyone needs:

Just use require('./i18next'); once in the client-side and it will give you the i18next variable globally.

Edited by ekoozu

Share this post


Link to post
Share on other sites

Seems that you are requiring it wrong. Please check documentation

Share this post


Link to post
Share on other sites
17 минут назад, Jengas сказал:

Yep, that's good

Thx! :3

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.