Socket
Socket
Sign inDemoInstall

github.com/yext/i18n

Package Overview
Dependencies
0
Alerts
File Explorer

Install Socket

Detect and block malicious and high-risk dependencies

Install

    github.com/yext/i18n

Package i18n offers the following basic internationalization functionality: There's more we'd like to add in the future, including: In order to interact with this package, you must first get a TranslatorFactory instace. Through the TranslatorFactory, you can get a Translator instance. Almost everything in this package is accessed through methods on the Translator struct. About the rules and messages paths: This package ships with built-in rules, and you are welcome to use those directly. However, if there are locales or rules that are missing from what ships directly with this package, or if you desire to use different rules than those that ship with this package, then you can specify additional rules paths. At this time, this package does not ship with built-in messages, other than a few used for the unit tests. You will need to specify your own messages path(s). For both rules and messages paths, you can specify multiple. Paths later in the slice take precedence over packages earlier in the slice. For a basic example of getting a TranslatorFactory instance: For simple message translation, use the Translate function, and send an empty map as the second argument (we'll explain that argument in the next section). You can also pass placeholder values to the translate function. That's what the second argument is for. In this example, we will inject a username into the translation. You can also translate strings with plurals. However, any one message can contain at most one plural. If you want to translate "I need 5 apples and 3 oranges" you are out of luck. The Pluralize method takes 3 arguments. The first is the message key - just like the Translate method. The second argument is a float which is used to determine which plural form to use. The third is a string representation of the number. Why two arguments for the number instead of one? This allows you ultimate flexibility in number formatting to use in the translation while eliminating the need for string number parsing. You can use the "FomatNumber", "FormatCurrency" and "FormatPercent" methods to do locale-based number formatting for numbers, currencies and percentages. If you need to sort a list of strings alphabetically, then you should not use a simple string comparison to do so - this will often result in incorrect results. "ȧ" would normally evaluate as greater than "z", which is not correct in any latin writing system alphabet. Use can use the Sort method on the Translator struct to do an alphabetic sorting that is correct for that locale. Alternatively, you can access the SortUniversal and the SortLocale functions directly without a Translator instance. SortUniversal does not take a specific locale into account when doing the alphabetic sorting, which means it might be slightly less accurate than the SortLocal function. However, there are cases in which the collation rules for a specific locale are unknown, or the sorting needs to be done in a local-agnostic way. For these cases, the SortUniversal function performs a unicode normalization in order to best sort the strings. In order to be flexible, these functions take a generic interface slice and a function for retrieving the value on which to perform the sorting. For example: When getting a Translator instance, the TranslatorFactory will automatically attempt to determine an appropriate fallback Translator for the locale you specify. For locales with specific "flavors", like "en-au" or "zh-hans", the "vanilla" version of that locale will be used if it exists. In these cases that would be "en" and "zh". When creating a TranslatorFactory instance, you can optionally specify a final fallback locale. This will be used if it exists. When determining a fallback, the the factory first checks the less specific versions of the specified locale, if they exist and will ultimate fallback to the global fallback if specified. All of the examples above conveniently ignore errors. We recommend that you DO handle errors. The system is designed to give you a valid result if at all possible, even in errors occur in the process. However, the errors are still returned and may provide you helpful information you might otherwise miss - like missing files, file permissions problems, yaml format problems, missing translations, etc. We recommend that you do some sort of logging of these errors.


Version published

Readme

Source

i18n

i18n support for golang applications. Supports message translation with placeholders and plurals, locale-specific string sorting, and number/currency formatting.

Copyright 2014 Vubeology, Inc.

Released under the MIT License (see LICENSE).

Usage

Read the full documentation here: http://godoc.org/github.com/vube/i18n

License

As stated about this golang package is released under the MIT License (see LICENSE).

Third Party Package Licenses

This i18n package makes use of third party packages in addition to the golang standard library and supplemental libraries. This package however does not modify or redistribute any third party package material.

While this i18n package is released under the MIT License, you must ensure that your use of this package also complies with the licenses under which each third party dependency is released.

launchpad.net/gocheck

This i18n package makes use of the launchpad.net/gocheck package, released under a Simplified BSD License. For specific license details, refer directly to the the gocheck package.

gopkg.in/yaml.v1

This i18n package makes use of the gopkg.in/yaml.v1 package, released under the LGPLv3 License. For specific license details, refer directly to the yaml package.

Call for open source help!

We could use some help. We do however have some guidelines if you want to contribute to our package.

For supplementing locale data:

If you have locale rules data that we are missing, we welcome all additional rules data in our standard yaml format. Please include comments in the yaml on how you sourced the data - AKA, you are a native speaker of a language, you got it from XYZ website, a professional translator provided the data, etc.

When supplementing locale data, you may add a locale who's language uses a set of plural rules that this package does not support. In this case, please add an additional plural rule function to the plurals.go file and add it to the plural rule map.

There is a unit test in rules_test.go that checks loading every single locale in this package. If you are adding a brand new locale to the list, please add it to this unit test.

For fixing bugs:

If you find a bug that you'd like to fix, please include a unit test that validates your work. This test should fail without the fix you provide and pass with the fix you provide.

For new features:

If you've decided to either tackle a feature on our wish list or you have a feature that you need in order to use our package, please provide a minimum of 80% unit test coverge over the code written for this new feature.

A note on unit testing:

We use the launchpad.net/gocheck package in our unit tests. We ask that you also use this package for tests that you write, for consistency sake.

FAQs

Last updated on 12 Jul 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc