Christian Gibbs
Christian Gibbs

Reputation: 11

Why isn't i18next-fs-backend loading translation files from Onedrive?

I'm trying to load i18next translation files from a directory in OneDrive. When I try to do so, playwright keeps looking for the files in the C:\ drive. Is it imposible to load files from OneDrive? Can anyone tell me what I am doing wrong?

See my code below:

const localePath = path.resolve('./locales');
// resolves correctly to C:\Users\myuserpath\OneDrive - MyStuff\QA-Automation\locales

i18next
    .use(FsBackend)
        .init({
        lng: 'en',
        ns:['signin.page', 'chat.page','session.page', 'landing.page', 'userprofile.page'],   
        FsBackend:{ 
           FsBackendOptions: {loadPath: path.join(localePath, '/{{lng}}/{{ns}}.page.json'),},
        }
    })

//Expected result: 
//Translations should load from C:\Users\myuserpath\OneDrive - MyStuff\QA-Automation\locales\en\NAMESPACEFILE.page.json
//Actual result: 
//[Error: ENOENT: no such file or directory, open 'C:\locales\en\NAMESPACEFILE.page.json'

Other things I have tried:

Using onedrive:

const myOneDrive = process.env.OneDriveCommercial;
const longerpath = path.join(myOneDrive, '/QA-Automation/locales/{{lng}}/{{ns}}.page.json');
i18next
    .use(FsBackend)
    .init({
     //blah blah
        FsBackend:{ FsBackendOptions: {loadPath: longerpath},},
    })

Hardcoding the full path:

const fullpath = 'C:\Users\myuserpath\OneDrive - MyStuff\QA-Automation\locales'
    FsBackend:{ FsBackendOptions: {loadPath: fullpath},},

Hardcoding the full path in init:

FsBackendOptions: {loadPath: 'C:/Users/myuserpath/OneDrive - MyStuff/QA-Automation/locales/{{lng}}/{{ns}}.page.json,},

Swearing:

const dev_reaction = '$#!(#&*$@$!!!'

The result is always the same. It ignores the Onedrive completely, and tries to load from c:\locales\etc.

Upvotes: 0

Views: 21

Answers (1)

Christian Gibbs
Christian Gibbs

Reputation: 11

This isn't really an answer, it's more like a workaround, but here's how I eventually got it to work:

Instead of using the "FSBackend{FSBackendOptions{}}" nodes, I simply went with the standard "backend" node in the .init method. That seems to have solved the problem.

i18next 
.use(FSBackend)
.init({
lng='en'
    backend:{loadPath: "C:\Users\myuserpath\OneDrive - MyStuff\QA-Automation\locales\en\NAMESPACEFILE.page.json",},
 }

This may be a bug or issue with the FSBackend or the FSBackendOptions. I will have to research it a little more and see if others are experiencing the issue, and perhaps file a bug report.

Upvotes: 1

Related Questions