Giter VIP home page Giter VIP logo

Comments (11)

jamuhl avatar jamuhl commented on August 15, 2024

you can use https://github.com/i18next/i18next-node/blob/master/lib/i18next.js#L314

in combination with the ensureSupportedLanguage Middleware on line 325

from i18next-node.

lenovouser avatar lenovouser commented on August 15, 2024

This doesn't fix everything I think.

I now added

ensureLngSupport: true

to the configuration.

Basically what it does now is:

/en/team (200) 👍
/en/team/xxx (404) 👍
/ (200) 👍
/xxx (200, should be 404) 👎
/en/ (404, should be 200) 👎

Hope this isn't too hard to understand.

from i18next-node.

jamuhl avatar jamuhl commented on August 15, 2024

i18n.addRoute('/:lng/' will result in /en route not /en/

why /xxx is allowed idk.

from i18next-node.

jamuhl avatar jamuhl commented on August 15, 2024

might need to add some more test cases here: https://github.com/i18next/i18next-node/blob/master/test/i18next.server.spec.js#L40 but on holiday right now...so not sure i get to it right now.

from i18next-node.

lenovouser avatar lenovouser commented on August 15, 2024

Hm. /de and /de/ do render, but in English, not German. Thats why I think that something is buggy because after the / everything is allowed and it renders over the Controller.home.

from i18next-node.

jamuhl avatar jamuhl commented on August 15, 2024

not sure...https://github.com/i18next/i18next-node/blob/master/test/i18next.server.spec.js#L70 tests this and tests are ok...but might be i miss something in the test cases.

from i18next-node.

lenovouser avatar lenovouser commented on August 15, 2024

I tested a bit more, and broke it down to one line:

with

ensureLngSupport: true

the code which is causing this is:

i18n.addRoute('/:lng/', Config.get('languages'), app, 'get', Controllers.home);

This is also true when you use it without the slash at the end

(/:lng)

from i18next-node.

jamuhl avatar jamuhl commented on August 15, 2024

as far i know that's regular behaviour in express. /something/ allows /something. you might try a regex route like /:lng/*

from i18next-node.

lenovouser avatar lenovouser commented on August 15, 2024

Hm. I just also just discovered that you can put anything in /:lng/ ( Like /isaduh/team/ ) and it will also render in English.

from i18next-node.

jamuhl avatar jamuhl commented on August 15, 2024

anything passed to /:lng/ will be taken as param. So some invalid language there will fallback to your fallback language. the /:lng will not be translated or replaced as all params be kept as params for express -> /:lng will be needed to grab the language.

might optimize that after upcoming version v2 of i18next.

from i18next-node.

jamuhl avatar jamuhl commented on August 15, 2024

upcoming v2: http://i18next.github.io/i18next.com/

i18next-node will be replaced by https://github.com/i18next/i18next-express-middleware

PRs welcome

from i18next-node.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.