Giter VIP home page Giter VIP logo

i18n's Issues

Overwrite locales!?

I'm defined my locale in english as:

{
  "BAD_PARAMETERS": 'BAD_PARAMETERS',
  "USER_NOT_FOUND": 'USER_NOT_FOUND',
  "MISSING_AUTH_HEADER": 'MISSING_AUTH_HEADER',
  "USER_EXISTS": 'USER_EXISTS',
  "SCAN_REFERENCE_EXISTS": 'Reference identifier exists to this provider',
  "TOO_MANY_RETRIES": 'TOO_MANY_RETRIES',
  "WRONG_AUTH_TYPE": 'WRONG_AUTH_TYPE',
  "WRONG_ISSUER": 'WRONG_ISSUER',
  "WRONG_AUDIENCE": 'WRONG_AUDIENCE',
  "WRONG_SCOPE": 'WRONG_SCOPE',
  "WRONG_IP": "WRONG_IP",
  "INVALID_TOKEN": "INVALID_TOKEN",
  "UNKNOW_PROVIDER": "Provider doesn't found or invalid",
}

When I try to use ctx.i18n.__(key) the en file was overwrited. Why? Thanks in advance.

{
  "UNKNOW_PROVIDER": "Provider doesn't found or invalid"
}

TypeError: ctx.i18n[(SET_PREFIX + key)] is not a function

"koa-i18n": "2.1.0",

browse:
http://localhost:3000/download/view?filePath=20220406/3_mP8fZGCY.jpg

  TypeError: ctx.i18n[(SET_PREFIX + key)] is not a function
      at D:\workspace\nodejs\project\project-backend\node_modules\koa-i18n\index.js:107:59
      at Array.some (<anonymous>)
      at i18nMiddleware (D:\workspace\nodejs\project\project-backend\node_modules\koa-i18n\index.js:104:24)
      at dispatch (D:\workspace\nodejs\project\project-backend\node_modules\koa-compose\index.js:42:32)
      at session (D:\workspace\nodejs\project\project-backend\node_modules\koa-session\index.js:41:13)
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async bodyParser (D:\workspace\nodejs\project\project-backend\node_modules\koa-bodyparser\index.js:91:5)
      at async cors (D:\workspace\nodejs\project\project-backend\node_modules\@koa\cors\index.js:108:16)
      at async compressMiddleware (D:\workspace\nodejs\project\project-backend\node_modules\koa-compress\lib\index.js:52:5)

How to define options dynamically?

How to define directory option dynamically?

i18n(app, {
  directory: path.join(__dirname, 'config', 'locales'),
  locales: ['en', 'pt-BR'],
  modes: ['header']
})

example error.

the exemple is missing a caracter.. !

app.use(i18n(app, {
...

no

app.use(18n(app, {

Define language directory dynamically

As asked in #11, then my question is pretty much the same, I use Nunjucks to have multiple themes on the same instance, that be, a frontend theme and a backend theme.

The language files should be a part of the theme directory and not something you store globally outside the theme itself.

As per now, the theme is defined in a middleware and set in a state, and used by all other elements.

app.use( function( ctx, next ) {
  ctx.state.theme = 'default';
  await next();
} );

How would I go about accessing ctx.state.theme when initializing koa-i18n inside the middleware, pseudo example code

app.use( i18n( app, {
  directory: `./themes/${ctx.state.theme}/languages`,
} ) );

Failed to make it work with Koa2

With the code same to the example, I still got this error:

TypeError: this.request[(GET_PREFIX + m)] is not a function

koa-i18n

Koa version: v2
koa-i18n version: 2.0.1
Node version: 7.7.4

Fallback scheme

How would i go about the following,

I have the following locales defined (en.json, nl.json, fr.json), If a user pops up using Accept-Language nl-BE it will fallback to en due to it being the default language.

How do i make it so that nl-BE (iso 639-4) falls back to the language code nl ? Do i use the modes array for this ?

Feature: dynamically detect locale getters/setters

I think it's possible to decouple this module from koa-locale by dynamically detecting getLocaleFrom... and setLocaleFrom.... This way, people can add more ways of determining locales in their middleware instead of having to rely on this module to keep a close watch on koa-locale.

What do you think? I can send in a pull request tonight if you think this is a good idea.

Here's a quick sample code:

var getLocaleMethods = function (request) {
  var methods = [];

  assert(typeof request === 'object', 'request param is not a valid request object');

  request.forEach(function (method) {
    if (method.indexOf('getLocaleFrom') === 0) {
      methods.push(method.replace('getLocaleFrom', ''));
      return;
    }
  });

  return methods;
};

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.