php-gettext / Languages

gettext language list automatically generated from CLDR data
https://php-gettext.github.io/Languages/
Other
70 stars 10 forks source link

Add Ruby Exporter #39

Closed MichaelHoste closed 3 years ago

MichaelHoste commented 3 years ago

Export a .rb file that can be easily imported in your Ruby application.

if you feel that it can be used by someone else than me 😉

mlocati commented 3 years ago

Thanks!

mlocati commented 3 years ago

Just one quick question: how does Ruby behave with the ternary operator? Like PHP or like C (see https://github.com/php-gettext/Languages#parenthesis-in-ternary-operators)?

If it behaves like C, we could suggest users to use --parenthesis=no for Ruby in the readme.

For example, without the --parenthesis flag (or with --parenthesis=yes) we have:

  'iu' => {
    'name' => 'Inuktitut',
    'formula' => '(n == 1) ? 0 : ((n == 2) ? 1 : 2)',

With --parenthesis=no:

  'iu' => {
    'name' => 'Inuktitut',
    'formula' => 'n == 1 ? 0 : n == 2 ? 1 : 2',
MichaelHoste commented 3 years ago

Just one quick question: how does Ruby behave with the ternary operator? Like PHP or like C (see https://github.com/php-gettext/Languages#parenthesis-in-ternary-operators)?

It behaves like C, so the --parenthesis=no would make sense for shorter syntax. But both options would work, right?

mlocati commented 3 years ago

Yep, both would work, but removing unneeded parenthesis makes the code a bit more readable (I do hate that PHP behavior with ternary operator, and I'm not the only one). See 4ad818b

MichaelHoste commented 3 years ago

I agree this is more readable once you're used to it!

I understand your hate of the PHP ternary operator, it's absolutely counter-intuitive and your example on the README was really surprising to me. It's a good thing it's deprecated on PHP 7 and triggers a fatal error on PHP 8 (cf. https://3v4l.org/QAAnA)