I'm using i18next-node for localization of my app.
I have two languages: en-CA and fr-CA
I'm using this to init the app:
i18next.init({
saveMissing: true,
sendMissingTo : 'all',
ignoreRoutes: ['img/','images/', 'public/', 'css/', 'js/'],
debug: true,
lng: 'en-CA'
});
The problem is, when I start the app, it gives me this error:
currentLng set to: en-US
[ { [Error: ENOENT, open 'locales/en-US/translation.json']
errno: 34,
code: 'ENOENT',
path: 'locales/en-US/translation.json' } ]
I don't want en-US, I want en-CA. Now, my app isn't showing either language. How do I set en-CA to be the default?
Turns out you can set fallbackLng : 'en-CA' and that will work. Kind of a hack though.
Try to read the detect language section under http://i18next.com/node/pages/doc_init.html
i18next detects during the request the language from your browser-settings (if not set by any other methode - cookie, querystring). That's why language is set to 'en-US'.
You can set the supported languages on init:
i18n.init({supportedLngs: ['en-CA', 'fr-CA']})
But you still need to set a fallbackLng -> eg. if someone requests your page with language set 'de' some fallback language should be displayed.
Related
Modern ECMAScript-262 from 6 version supports Proxy object, which allows to intercept custom object invocations (https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Proxy )
By using Proxy-object, user can write something like obj.func1(123).func2('ABC').something, there nothing right to obj is not existing actually. Of course, by proper Proxy declaration, this chain can exist. The simplest way is return new Proxy on every property access and function invocation.
But is there way to automate this process, maybe some NPM library? The goal is transform custom free-form expression with Proxy to declarative string.
Upper example will transform to something like:
const result = obj.func1(123).func2('ABC').something;
result.__INVOCATION_VIEW__ === [
{ type: 'function', name: 'func1', args: [123] },
{ type: 'function', name: 'func2', args: ['ABC'] },
{ type: 'get', name: 'something' }
]
Pure theoretically, solution is possible anyway, because any entity in invocation chain is available as string in subsequent Proxy. But implementation is much complex. Maybe there is existing library for it?
I am using Roots to develop an app, as I run roots watch command, then it compiles successfully and opens the localhost:1111 page, but with the error below:
Cannot GET /
This is how my app.coffee file looks like, though I looked for a fix for this in SOF and none of them seemed to work for this case.
axis = require 'axis'
rupture = require 'rupture'
autoprefixer = require 'autoprefixer-stylus'
js_pipeline = require 'js-pipeline'
css_pipeline = require 'css-pipeline'
module.exports =
ignores: ['readme.md', '**/layout.*', '**/_*', '.gitignore', 'ship.*conf']
extensions: [
js_pipeline(files: 'assets/js/*.coffee'),
css_pipeline(files: 'assets/css/*.styl')
]
stylus:
use: [axis(), rupture(), autoprefixer()]
sourcemap: true
'coffee-script':
sourcemap: true
jade:
pretty: true
Is it a different solution since this is CoffeeScript instead of JS?
So it turns out to be the fact that I needed to cd project-name after I have done roots new project-name, and then only roots watch would work.
Such a rookie mistake, but a good lesson.
This is about using i18next in a node.js backend.
This is the initialization:
i18next.init({
lng: 'de',
fallbackLng: ['de'],
ns: {
namespaces: ['formal', 'informal'],
defaultNs: 'formal'
},
fallbackToDefaultNS: true,
resStore: {
de: resourcesDE,
en: resourcesEN
}
});
where resourcesDE is an object with structure { formal: { }, informal: { }} and resourcesEN has the same structure but only 'formal', no 'informal' (but I have this problem even if there is 'informal' in resourcesEN).
Now, what I want to have is:
If I request the translation of 'informal:myKey' for English that the search route (== fallback) is:
(en)'informal:myKey' > (en)'myKey' > (de)'informal:myKey' > (de)'myKey'
or
(en)'informal:myKey' > (en)'myKey' > (de)'myKey'
but what actually happens is:
(en)'informal:myKey' > (de)'informal:myKey' > (de)'myKey'
meaning that the language changes before even trying to get a text of the same language from a different (the default) namespace.
How can I achieve this or something along those lines. I've also tried using a context instead of namespaces for these alternatives, but that seemed to behave the same. I'm glad to be proven wrong though.
The solution that worked out for me, in the end:
Instead of namespaces, I use special language flavors: 'de-INFORMAL' and 'en-INFORMAL'. If no label is found under 'en-INFORMAL', the lookup falls back to 'en', first and out of the box. If fallbackLng is set to 'de' it will fallback to that if the label in not found in 'en', either.
I'm using the jquery-validation-engine plugin and after validate I need to add a class to the inputs with the error promt to add for example a red border or something like that, is there a way using the plugin configuration to setup this?
I alsow use that same plugin.
Do you have the last verion off the plug-in ?
In the file: jquery.validationEngine.js
you will find almost at the bottom:
InvalidFields: [],
onFieldSuccess: false,
onFieldFailure: false,
onSuccess: false,
onFailure: false,
addSuccessCssClassToField: false,
addFailureCssClassToField: false,
These are the 'master' settings for the options you are looking for.
My current setup is like:
InvalidFields: [],
onFieldSuccess: true,
onFieldFailure: true,
onFormSuccess: false,
onFormFailure: false,
addSuccessCssClassToField: 'inputbox-success',
addFailureCssClassToField: 'inputbox-error',
And then the two css classes in youre css file ( 'inputbox-error' & 'inputbox-succes').
This works just fine over here..
Good Luck...
And if you have any more question about this plugin or other functions off it just ask .. :P
Greets,
Marco
I have a language selector in my project to redirect to index page with the locale parameter {_locale}, but when the link is to default locale seted in routing.yml, the link looks different. This is my code:
I generate the link in code:
<a href="{{ path('ProjectBaseBundle_index', {'_locale': country.idlang}) }}">
...
</a>
And here is the routing.yml:
ProjectBaseBundle_index:
pattern: /{_locale}
defaults: { _controller: ProjectBaseBundle:Default:index, _locale: es }
requirements:
_locale: en|fr|de|es
This generate propertly the routes for all languages, buy for the default one looks different:
http://project.dev/app_dev.php/en
http://project.dev/app_dev.php/fr
http://project.dev/app_dev.php/de
http://project.dev/app_dev.php/?_locale=es
es is our default language code. I'm using Symfony 2.1
Anyone know How to generate identical route for the default lang?
It happens because of conditions for requirements and provided parameters in UrlGenerator - unknown parameters passed through the arguments array are automatically appended at the end of the URL as GET parameters.
Did you try to put default locale in config.yml instead of having it in defaults section of route?
Symfony-2.0:
framework:
session: { default_locale: es }
Symfony-2.1:
framework:
default_locale: es
I just discovered that it makes sense, because the parameter {_locale} does not exists for the default language, so the system appended the parameter as a GET parameter.
I found a workaround:
ProjectBaseBundle_default:
pattern: /{_locale}
defaults: { _controller: ProjectBaseBundle:Default:index , _locale: %locale% }
ProjectBaseBundle_index:
pattern: /{_locale}
defaults: { _controller: ProjectBaseBundle:Default:index }
requirements:
_locale: en|fr|de|es
and I have opened a issue in Symfony board: https://github.com/symfony/symfony/issues/5135