rolepoint / pyseeyou Goto Github PK
View Code? Open in Web Editor NEWA Python ICU MessageFormat parsing tool
License: MIT License
A Python ICU MessageFormat parsing tool
License: MIT License
from pyseeyou import format
result = format('''{GENDER, select,
male {He}
female {She}
other {They}
} found {NUM_RESULTS, plural,
one {1 result}
other {# results}
} in {NUM_CATEGORIES, plural,
one {1 category}
other {# categories}
}.''',
{'GENDER': 'male', 'NUM_RESULTS': 1, 'NUM_CATEGORIES': '2'}, 'en')
=> u'He found 1 result in 2 categories.'
In the readme the above example was given, a minimum example to recreate the problem is to pass
{'GENDER': 'non_binary', 'NUM_RESULTS': 1, 'NUM_CATEGORIES': '2'}, 'en')
non_binary
is not in [male, female]
so it should fallback to other
The problem is this line https://github.com/rolepoint/pyseeyou/blob/master/pyseeyou/node_visitor.py#L136 doesnt actually check if self.options[key]
exist in item
so it need to be changed from
if key in self.options:
return item[self.options[key]]
to something like
if key in self.options:
item_key = self.options[key]
if item_key:
return item[self.options[key]]
else:
return item['other']
Hi,
I saw in locale.py pyseeyou does not support Spanish. Is there a plan to add support for Spanish(es)?
thanks
When running pytest, I see the following:
pyseeyou/grammar.py:34
github/pyseeyou/pyseeyou/grammar.py:34: DeprecationWarning: invalid escape sequence \w
''')
<unknown>:1
<unknown>:1: DeprecationWarning: invalid escape sequence \w
<unknown>:1: DeprecationWarning: invalid escape sequence \w
<unknown>:1: DeprecationWarning: invalid escape sequence \w
<unknown>:1: DeprecationWarning: invalid escape sequence \.
<unknown>:1: DeprecationWarning: invalid escape sequence \s
This warning came about because of https://bugs.python.org/issue27364
Empty strings are incorrectly formatted, example:
>> s = '{number, plural, =1 {} other {#}}'
>> format(s, {'number': 1},' en')
'None'
Expected result is ''
File "/../my_file.py", line 103, in _process_message
return format(actual_message, processed_params, _get_message_format_locale(locale_code))
File "/.../lib/python2.7/site-packages/pyseeyou/init.py", line 13, in format
ast = ICUMessageFormat.parse(msg)
File "/.../lib/python2.7/site-packages/parsimonious/grammar.py", line 115, in parse
return self.default_rule.parse(text, pos=pos)
File "/.../lib/python2.7/site-packages/parsimonious/expressions.py", line 122, in parse
raise IncompleteParseError(text, node.end, self)
IncompleteParseError: Rule 'message_format_pattern' matched in its entirety, but it didn't consume all the text. The non-matching portion of the text begins with '{n,}: in regular ex' (line 1, column 14).
String example: "Disallowed: \\{n,\\}: in regular expression"
This should be supported as described here:
Supports escape sequences for message syntax chars, e.g.: "\{foo\}" will output: "{foo}" in the formatted output instead of interpreting it as a foo argument.
The CLDR provides an XML file (current version can be found in the most recent vXX ZIP downloaded from here: http://cldr.unicode.org/index/downloads, navigate to core/supplemental/plurals.xml
) listing each of the locales and their respective plurality rules.
This file is structured so that languages with equivalent rules are even grouped together. The plurality rules are even formatted in accordance with an expression language, which could be used to parse them quite easily.
This means that we can much more effectively generate the plurality functions from this file, rather than type them all out by hand in locales.py
and store/update them as and when/if they change.
Ideally this would be a script that generates a working locales.py
file post/during pip-install, and automatically pulls down and uses the latest CLDR plurals.xml
file as a base.
Need reworking of the usage of the unicode
keyword around the codebase, meaning that the library is not currently Python 3 compatible.
Formatted Argument are used to format dates, numbers, time and even custom formats.
usage example:
format('found {count, number} records', {'count': 6}, 'en')
I can't find a license for this library. It would be great to add one so people know if it's freely useable.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.