Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added error for non-existing locale #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ language requirements. Plurr formatters are implemented in:
**Go, Java, JavaScript, Perl, PHP, and Python**. Feel free to contribute
to this project and provide support for your favorite languages.

The plural forms we use can be found at the [Translate Project page](http://docs.translatehouse.org/projects/localization-guide/en/latest/l10n/pluralforms.html).

[Try live demo →](http://iafan.github.io/plurr-demo/)
===============

Expand Down
2 changes: 1 addition & 1 deletion go/plurr/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var ErrEmptyPlaceholderName = errors.New("Empty placeholder name")
var ErrEmptyListOfVariants = errors.New("Empty list of variants")

// ErrPlaceholderValueNotDefined is returned by Format function
// when neither palaceholder not its prefix variant (sans '_PLURAL')
// when neither placeholder not its prefix variant (sans '_PLURAL')
// is not defined
type PlaceholderValueNotDefinedError struct {
name string
Expand Down
3 changes: 3 additions & 0 deletions js/plurr.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@
// Choose the plural function based on locale name
//
this.setLocale = function(locale) {
if (!(locale in pluralEquations)) {
throw new TypeError("Unknown locale '" + locale + "'");
}
this.plural = pluralEquations[locale];
}; // function locale

Expand Down
3 changes: 3 additions & 0 deletions php/Plurr.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ function __construct($options = null) {
// Choose the plural function based on locale name
//
public function set_locale($locale) {
if (!(array_key_exists($locale, $this->plural_equations))) {
throw new Exception("Unknown locale '" . $locale . "'");
}
$this->plural = $this->plural_equations[$locale];
} // function locale

Expand Down
7 changes: 5 additions & 2 deletions python/plurr.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,11 @@ def add_missing_options(self, opt, defaults):

def set_locale(self, locale):
"""Choose the plural function based on locale name."""
self._plural = self._plural_equations[locale]
# TODO: raise error on missing locale
try:
self._plural = self._plural_equations[locale]
except KeyError:
if strict:
raise KeyError(u"Unkown locale '"+ locale +"'")

def format(self, s, params, options=None):
if options is None:
Expand Down