Comments (3)
For example
Do you want to delete {N_PLURAL:this {N} file|these {N} files} permanently?
would be written as
printf(
ngettext(
"Do you want to delete this %d file permanently?",
"Do you want to delete these %d files permanently?",
N),
N);
in traditional GNU gettext.
from plurr.
Great question! Here are some points to consider:
- As you can see in your own example, gettext is quite explicit: all plural choices are stored as separate full strings. This might be easier to translate in certain cases (where strings are short and simple), but is very inflexible. You can't have two different plural-based choices in the same string, i.e. "Do you want to delete N file(s) in M folder(s) permanently?" is something that can be easily expressed in Plurr, but not in
ngettext()
. ngettext()
expects you to have your source in a language that only has two plural forms (the function in e.g. C is declared asngettext (const char *msgid1, const char *msgid2, unsigned long int n)
. So you can't really use it in a source language that has more plural forms.- gettext is all about extracting strings from the source and using them with .po files as a part of gettext suite. Plurr is file format-agnostic (you can use Plurr-formatted strings in any platform with any resource file types), and most importantly, it guarantees the same 1:1 string mapping in resource files (i.e. there's no need to use resource file formats that have native support for plurals).
- Plurr can handle not only plural-based choices, but all arbitrary choices. For example, you can create a strings for different genders, or do special cases for N=0,1,2,...
- Plurr is a really tiny library, as compared to the gettext suite of libraries and tools. In some cases, it might be a very compelling reason of its own.
- in addition to
ngettext()
you need some formatting function to actually put placeholders in place (in your example,printf()
).sprintf()
-style placeholders are really bad for localization purposes (for example, you can't swap two%s
placeholders). So you still need something different for proper localization. Plurr solves that problem as well, offering named placeholders that provide more context and can be reordered in the translation as needed.
from plurr.
Closing due to inactivity. I believe the question has been answered.
from plurr.
Related Issues (6)
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 plurr.