Comments (7)
Be careful about the base
option, that will cause you somme trouble.
But if you make a decent PR (please, include tests / version push / documentation); that would be an amazing feature !
from i18n-node-2.
After some more thought, I think my initial considerations may be too simplistic. The fact that real language is supported within the key name makes any kind of delimiter difficult as in the first option, and since __()
supports the sprintf
syntax makes the second option difficult.
It doesn't look like this fork supports the passing of the options object when translating a string, as in __({ phrase: 'hello', locale: 'fr' })
as I could have put an extra option on there for the file you wish to pull from.
One option I'm considering is to just implement another method alongside __()
and __n()
which accepts an argument indicating the file, e.g. __f('labels', "Let's go to %s", 'Spain')
where the first argument is the file and following arguments are the translation arguments.
Another thing I'm thinking about is whether to only support a flat file structure or nest directories. The directory structure could influence how the locale keys are named which might aid organisation, and accessing the language keys would utilise a path-style syntax.
For example, consider the following folder structure:
locale
|-- geo
| | countries-en.js
| | countries-fr.js
|-- de.js
|-- en.js
|-- fruits-en.js
|-- fruits-de.js
To access the key Spain
inside countries
, one might use __('geo/countries/Spain')
, which would search inside the geo/countries
local files. Accessing the 'fruits' language keys would be __('fruits/Apple')
. It would also get around the problem of having to have another method as in the above example.
@gjuchault Oh yes, full tests and whatnot will be written
from i18n-node-2.
So you think about __f
and __fn
(because you must reimplement __
and
__n
) ?
I do prefer the options object as first argument. But that would be : __({ key: 'foo', path: 'geo/countries/spain' }) No use of
locale(use
setLocale` instead)
Did you think about using requires in one file instead and using that file
as locale ?
Le mar. 4 août 2015 à 11:04, Steve Hobbs [email protected] a
écrit :
After some more thought, I think my initial considerations may be too
simplistic. The fact that real language is supported within the key name
makes any kind of delimiter difficult as in the first option, and since
__() supports the sprintf syntax makes the second option difficult.It doesn't look like this fork supports the passing of the options object
when translating a string, as in __({ phrase: 'hello', locale: 'fr' }) as
I could have put an extra option on there for the file you wish to pull
from.One option I'm considering is to just implement another method alongside
__() and __n() which accepts an argument indicating the file, e.g. __f('labels',
"Let's go to %s", 'Spain') where the first argument is the file and
following arguments are the translation arguments.Another thing I'm thinking about is whether to only support a flat file
structure or nest directories. The directory structure could influence how
the locale keys are named which might aid organisation.For example, consider the following folder structure:
locale
|-- geo
| | countries-en.js
| | countries-fr.js
|-- en.js
|-- de.jsTo access the key Spain inside countries, one might use
__('geo/countries/Spain'), which would search inside the geo/countries
local files.—
Reply to this email directly or view it on GitHub
#65 (comment).
from i18n-node-2.
I was thinking about __f
and __fn
as a last resort, just to distinguish from the base methods, since it would be difficult to implement the new functionality based on the arguments alone, but I don't think that will be necessary if we were to reference the keys by a path name.
Using requires would be interesting.. I wonder if this whole issue could be solved using a build step which effectively concatenates the language files together. The benefits of all this only really come into effect at design time, after all.
from i18n-node-2.
Using requires would be interesting.. I wonder if this whole issue could be solved using a build step which effectively concatenates the language files together. The benefits of all this only really come into effect at design time, after all.
Interesting, however in my scenario I would like the language files separated for different reasons. I need a clear separation between my templates and their localisation files , so that they can use the same keys, and provide different translations.
from i18n-node-2.
@blowsie could you give a short example; I did not get the interest to have a template file
from i18n-node-2.
I think its necessary separated files in production.
Options:
- Developer defines the files and pattern to retrieve, for example using glob
- Use a file prefix in keys, for example for file en/demo.js, the title key is demo.title.
- Add a config parameter for define logical
- Remove the write option and create a cli package for work with literals using yeoman
from i18n-node-2.
Related Issues (20)
- Support language fallbacks HOT 4
- Requesting changelog for npm version 0.7.0 HOT 2
- How to access i18n object in React components? HOT 1
- Feature Request: override current language manually HOT 2
- Did module create tmp files?
- What is the proper way to call i18n-2 accross main.js and renderer.js HOT 1
- i18n should be silent by default HOT 2
- Using i18n in js files HOT 3
- Uncaught ReferenceError: __ is not defined HOT 3
- unexpected error writing files HOT 1
- Large HB project, seems to write to JSON file over and over even with no changes HOT 6
- Issue with getting value from i18n.__("Hello") HOT 3
- The sprintf package is deprecated in favor of sprintf-js HOT 2
- setLocaleFromQuery() isn't working HOT 1
- New strings go to user-defined language
- When in Dev Mode JSON is overwritten when accidentally invalidating the JSON language file.
- Problem merging locale file with base file
- Access to the i18n outside of a request
- i18n-2 upd
- how to add support for ICU Format
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from i18n-node-2.