Coder Social home page Coder Social logo

Comments (5)

tomatau avatar tomatau commented on May 18, 2024

OK - found the solution - I need to add this namespace manually - this isn't very clearly documented as the file links to another module - could it not be jiggled to work with the default of "one", "other", "zero" ?

from counterpart.

marianhlavac avatar marianhlavac commented on May 18, 2024

I wasn't able to figure it out. Wtf, how does this damn thing works? The documentation around this is really bad.

What should be in counterpart.pluralize ?

from counterpart.

tomatau avatar tomatau commented on May 18, 2024

I do something like this:

const localeDefaults = {
  counterpart: {
    pluralize: (entry, count)=> entry[
      (count === 0 && 'zero' in entry)
        ? 'zero' : (count === 1) ? 'one' : 'other'
    ],
    formats: {
      date: {
        'default':  '%a, %e. %b %Y',
        'long':     '%A, %e. %B %Y',
        'short':    '%d.%m.%y'
      },
      time: {
        'default':  '%H:%M',
        'long':     '%H:%M:%S %z',
        'short':    '%H:%M'
      },
      datetime: {
        'default':  '%a, %e. %b %Y, %H:%M',
        'long':     '%A, %e. %B %Y, %H:%M:%S %z',
        'short':    '%d.%m.%y %H:%M'
      }
    }
  }
}
const nlJSON = Object.assign(
  require('./locales/phrase.nl.json'), localeDefaults
)
counterpart.registerTranslations('nl', nlJSON);

from counterpart.

marianhlavac avatar marianhlavac commented on May 18, 2024

Thank you kindly, sir! 😃

from counterpart.

yanndinendal avatar yanndinendal commented on May 18, 2024

After struggling with this problem a bit (as my translations are in a json file, and functions are not serializable), I've found a simpler solution (one line) to this:

  const translator = new Counterpart.Instance();
  availableLanguages.forEach((currentLocale) => {
    translator.registerTranslations(currentLocale, translations[locale]);
  });
  translator.setLocale(locale);

  // That's it! Just add that line and all locales will use Counterpart's default
  // English locale's pluralize function. :)
  translator.setFallbackLocale('en');

from counterpart.

Related Issues (20)

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.