快速复数规则:计算基数的复数规则,以便本地化库可以选择正确的复数形式

  • Q8_758632
    了解作者
  • 116.8KB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-06-14 12:47
    上传日期
快速复数规则 计算特定于语言环境的复数规则,以识别代表项目计数的基数的正确复数形式。 国际化库可以利用它来选择正确的本地化字符串。 专注且完整-包含,但仍。 小而又-压缩后为7.27 kB,最小4.8 kB,1.32 kB。 使用作为以使用选择。 使用和编写的标准文档和书面。 可靠且正确-包含,并在Node.js和浏览器中运行。 通用和现代-支持复数形式索引(0-5)和复数形式规则( zero , one , two , few , many和other ),并包括声明。 如果您正在寻找一个编译并执行声明性,请参见。 以编程方式生成以提高可靠性,但又越来越大。 目录 概要 con
fast-plural-rules-master.zip
  • fast-plural-rules-master
  • .eslintrc.yml
    18B
  • .gitignore
    138B
  • .babelrc
    100B
  • package.json
    3.5KB
  • package-lock.json
    297.8KB
  • src
  • cardinals.js
    22.3KB
  • index.js
    2.4KB
  • index.d.ts
    1KB
  • .travis.yml
    188B
  • tslint.yml
    32B
  • LICENSE
    1.1KB
  • util
  • generate-browser-tests.js
    3.4KB
  • generate-plural-rule-definitions.js
    1001B
  • parse-plural-rule.js
    1.9KB
  • read-rules-from-description.js
    1.1KB
  • read-rules-from-comments.js
    1KB
  • rollup.config.js
    1.2KB
  • perf
  • createSuite.js
    511B
  • index.js
    2.1KB
  • README.md
    7.5KB
  • .coveralls.yml
    25B
  • .vscode
  • settings.json
    318B
  • launch.json
    1KB
  • tasks.json
    525B
  • .npmignore
    81B
  • docs
  • usage.md
    11.6KB
  • speed.md
    748B
  • functions.md
    28KB
  • languages.md
    14.4KB
  • design.md
    10.1KB
  • API.md
    8.9KB
  • test
  • getPluralRuleForCardinalsByIndex.test.js
    462B
  • documentation.test.js
    2.2KB
  • getPluralRuleForNamedFormsForCardinalsByIndex.test.js
    514B
  • getPluralFormNameForCardinalByLocale.test.js
    840B
  • rules.test.js
    1019B
  • typings.test.ts
    950B
  • getPluralFormForCardinalByRuleIndex.test.js
    750B
  • getPluralFormForCardinalByLocale.test.js
    776B
  • browser.html
    665B
  • getPluralRuleForCardinalsByLocale.test.js
    776B
  • browser.test.js
    2KB
  • rulesByLocale.test.js
    1.7KB
  • getPluralFormNameForCardinalByIndex.test.js
    814B
  • getPluralRuleForNamedFormsForCardinalsByLocale.test.js
    854B
  • formsByIndex.test.js
    1023B
  • .editorconfig
    147B
内容介绍
# Fast Plural Rules [![NPM version](https://badge.fury.io/js/fast-plural-rules.png)](http://badge.fury.io/js/fast-plural-rules) [![Build Status](https://travis-ci.org/prantlf/fast-plural-rules.png)](https://travis-ci.org/prantlf/fast-plural-rules) [![Coverage Status](https://coveralls.io/repos/github/prantlf/fast-plural-rules/badge.svg?branch=master)](https://coveralls.io/github/prantlf/fast-plural-rules?branch=master) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/94ba20975c8b4feb8b8b280de2ffcb9b)](https://www.codacy.com/app/prantlf/fast-plural-rules?utm_source=github.com&utm_medium=referral&utm_content=prantlf/fast-plural-rules&utm_campaign=Badge_Grade) [![Dependency Status](https://david-dm.org/prantlf/fast-plural-rules.svg)](https://david-dm.org/prantlf/fast-plural-rules) [![devDependency Status](https://david-dm.org/prantlf/fast-plural-rules/dev-status.svg)](https://david-dm.org/prantlf/fast-plural-rules#info=devDependencies) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com) [![NPM Downloads](https://nodei.co/npm/fast-plural-rules.png?downloads=true&stars=true)](https://www.npmjs.com/package/fast-plural-rules) Evaluates locale-specific plural rules to identify the right plural form for a cardinal number, which represents an item count. Internationalization libraries can utilize it to choose the right localized string. * Focused and complete - [nothing but the rule evaluation](./src/index.d.ts) is included, but still [supporting almost 150 languages](./docs/languages.md#supported-languages). * Tiny and [fast](./docs/speed.md#plural-form-lookup-speed) - 7.27 kB, 4.8 kB minified, 1.32 kB, gzipped. Using [plain hand-coded functions](./src/cardinals.js) as [plural rules](./docs/design.md#plural-rules) to pick [plural forms](./docs/design.md#plural-forms) using [language locales](./docs/design.md#locales). * Standard and documented - written using the [Translate Project documentation] and the [Mozilla documentation]. * Reliable and correct - contains the [full test suite] [comparing the actual results with the Mozilla specification], run in both Node.js and the browser. * Universal and modern - supports both plural form index (0-5) and plural form rules (`zero`, `one`, `two`, `few`, `many` and `other`) and includes declarations for [TypeScript]. If you are looking for a library compiling and executing the declarative [CLDR plural rules], see [plural-rules]. Generated programmatically for better reliability, but bigger and slower. ### Table of Contents - [Synopsis](#synopsis) - [Installation and Getting Started](#installation-and-getting-started) - [Usage Scenarios](./docs/usage.md#usage-scenarios) - [Design Concepts](./docs/design.md#design-concepts) - [Supported Languages](./docs/languages.md#supported-languages) - [API Reference](./docs/API.md#api-reference) - [Library Integrations](#library-integrations) - [Contributing](#contributing) - [Release History](#release-history) - [License](#license) ## Synopsis ```js const { getPluralFormForCardinalByLocale } = require('fast-plural-rules') // Returns index of the plural form for the specified locale and cardinal. getPluralFormForCardinalByLocale('en', 1) // Returns 0; "1 file" getPluralFormForCardinalByLocale('en', 2) // Returns 1; "2 files" getPluralFormForCardinalByLocale('en', 5) // Returns 1; "5 files" getPluralFormForCardinalByLocale('cs', 1) // Returns 0; "1 soubor" getPluralFormForCardinalByLocale('cs', 2) // Returns 1; "2 soubory" getPluralFormForCardinalByLocale('cs', 5) // Returns 2; "5 souborů" // Returns a localized message for the specified locale and cardinal. localizeMessage('en', 'fileCount', 3) // Returns "3 files" localizeMessage('cs', 'fileCount', 3) // Returns "3 soubory" // Returns a localized message for the specified locale and cardinal. function localizeMessage (locale, messageKey, cardinal) { const pluralForm = getPluralFormForCardinalByLocale(locale, cardinal) const messageFormat = messages[locale][messageKey][pluralForm] return messageFormat.replace('{0}', cardinal) } // A language pack with a testing message. const messages = { en: { fileCount: [ "{0} file", // 0 - singular "{0} files" // 1 - plural ], } cs: { fileCount: [ "{0} soubor", // 0 - singular "{0} soubory", // 1 - plural for 2-4 items "{0} souborů" // 2 - plural for 5+ items ] } } ``` There is another [full example using plural form names](./docs/design.md#using-form-names) instead of numeric indexes like this: ```js // Localized messages organized by locales and message keys. const messages = { en: { fileCount: { one: '{0} file', // singular other: '{0} files' // plural } }, cs: { fileCount: { one: '{0} soubor', // singular few: '{0} soubory', // plural for 2-4 items other: '{0} souborů' // plural for 5 and more items } } } ``` ## Installation and Getting Started This module can be installed in your project using [NPM] or [Yarn]. Make sure, that you use [Node.js] version 6 or newer. ```sh $ npm i fast-plural-rules --save ``` ```sh $ yarn add fast-plural-rules ``` Functions are exposed as named exports, for example: ```js const { getPluralFormForCardinalByLocale } = require('fast-plural-rules') ``` You can read more about the [module loading](./docs/API.md#loading) in other environments, like with ES6 or in web browsers. [Usage scenarios](./docs/usage.md#usage-scenarios) demonstrate applications of this library in typical real-world situations. [Design concepts](./docs/design.md#design-concepts) explain the approach to the correct internationalization of messages with cardinals taken by this library. Translators will read about [plural rules for supported languages](./docs/languages.md#supported-languages) to be able to write the right plural forms to language packs. Finally, the [API reference](./docs/API.md#api-reference) lists all functions with a description of their functionality. ## Library Integrations * [Extended Day.js] - [relativeTime plugin] formats time durations to the past and to the future. ## Contributing In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt. ## Release History * 2019-07-31 v1.0.0 Correct rules for Baltic, Celtic, Semitic, Shuar and Welsh language families to match the latest Mozilla documentation, support CLDR plural form names, complete the test suite * 2018-10-28 v0.0.1 Initial release ## License Copyright (c) 2018-2019 Ferdinand Prantl Licensed under the MIT license. [Node.js]: http://nodejs.org/ [NPM]: https://www.npmjs.com/ [Yarn]: https://yarnpkg.com/ [TypeScript]: https://www.typescriptlang.org/ [full test suite]: https://travis-ci.org/prantlf/fast-plural-rules [comparing the actual results with the Mozilla specification]: https://github.com/prantlf/fast-plural-rules/blob/master/test/rules.test.js [Translate Project documentation]: http://docs.translatehouse.org/projects/localization-guide/en/latest/l10n/pluralforms.html#pluralforms-list [Mozilla documentation]: https://developer.mozilla.org/en-US/docs/Mozilla/Localization/Localization_and_Plurals#List_of_Plural_Rules [Extended Day.js]: https://github.com/prantlf/dayjs [relativeTime plugin]: https://github.com/prantlf/dayjs/blob/combined/docs/en/Plugin.md#relativetime [CLDR plural rules]: http://www.unicode.org/cldr/charts/latest/supplemental/language_plural_rules.html [plural-rules]: https://github.com/prantlf/plural-rules
评论
    相关推荐
    • node.js:Node.js
      node.js 如果发现错误,请将其保存在并提出拉取请求。 谢谢!
    • node.js:学习 Node.js
      节点.js 学习 Node.js :D
    • node.js开发指南
      Node.js是一种方兴未艾的新技术,诞生于2009年。经过两年的快速变化,Node.js生态圈已经逐渐走向稳定。Node.js采用了以往类似语言和框架中非常罕见的技术,总结为关键词就是:非阻塞式控制流、异步I/O、单线程消息...
    • Node.js 7.x异步/等待支持演示-Node.js开发
      Node.js v7 async / await演示这是什么? Node.js v7.xx附带实验性的异步/等待支持,大大简化了编写现代服务器端代码所需的样板。 该项目是Node.js v7 async / await演示的演示。这是什么? Node.js v7.xx附带实验性...
    • node.js
      node.js !!!
    • node.js
      node.js 실습 Node.js版本-기프로젝트지
    • node.js
      node.js
    • node.js
      node.js
    • node.js:node.js学习
      node.js node.js研究
    • Node.js
      Node.js