Giter Site home page Giter Site logo

Comments (3)

robert-j-engdahl avatar robert-j-engdahl commented on September 18, 2024

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.

iafan avatar iafan commented on September 18, 2024

Great question! Here are some points to consider:

  1. 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().
  2. ngettext() expects you to have your source in a language that only has two plural forms (the function in e.g. C is declared as ngettext (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.
  3. 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).
  4. 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,...
  5. 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.
  6. 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.

iafan avatar iafan commented on September 18, 2024

Closing due to inactivity. I believe the question has been answered.

from plurr.

Related Issues (6)

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.