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

Let ArrayGenerator generate prettier PHP code #8

Merged
merged 1 commit into from
Nov 6, 2023

Conversation

mlocati
Copy link
Member

@mlocati mlocati commented Nov 3, 2023

What about adding a couple of options to ArrayGenerator to make prettier PHP code?

Turns this:

<?php return array (
  'domain' => 'testingdomain',
  'plural-forms' => 'nplurals=3; plural=(n % 10 == 1 && n % 100 != 11) ? 0 : ((n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 12 || n % 100 > 14)) ? 1 : 2);',
  'messages' =>
  array (
    '' =>
    array (
      '%ss must be unique for %ss %ss.' => '%ss mora da bude jedinstven za %ss %ss.',
    ),
    'other-context' =>
    array (
      '日本人は日本で話される言語です!' =>
      array (
        0 => 'singular',
        1 => 'plural1',
        2 => 'plural2',
      ),
    ),
  ),
);

Into this (pretty set to true):

<?php

return [
    'domain' => 'testingdomain',
    'plural-forms' => 'nplurals=3; plural=(n % 10 == 1 && n % 100 != 11) ? 0 : ((n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 12 || n % 100 > 14)) ? 1 : 2);',
    'messages' => [
        '' => [
            '%ss must be unique for %ss %ss.' => '%ss mora da bude jedinstven za %ss %ss.',
        ],
        'other-context' => [
            '日本人は日本で話される言語です!' => [
                'singular',
                'plural1',
                'plural2',
            ],
        ],
    ],
];

Or this (strictTypes set to true):

<?php declare(strict_types=1); return array (
  'domain' => 'testingdomain',
  'plural-forms' => 'nplurals=3; plural=(n % 10 == 1 && n % 100 != 11) ? 0 : ((n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 12 || n % 100 > 14)) ? 1 : 2);',
  'messages' =>
  array (
    '' =>
    array (
      '%ss must be unique for %ss %ss.' => '%ss mora da bude jedinstven za %ss %ss.',
    ),
    'other-context' =>
    array (
      '日本人は日本で話される言語です!' =>
      array (
        0 => 'singular',
        1 => 'plural1',
        2 => 'plural2',
      ),
    ),
  ),
);

Or this (both strictTypes and pretty set to true):

<?php

declare(strict_types=1);

return [
    'domain' => 'testingdomain',
    'plural-forms' => 'nplurals=3; plural=(n % 10 == 1 && n % 100 != 11) ? 0 : ((n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 12 || n % 100 > 14)) ? 1 : 2);',
    'messages' => [
        '' => [
            '%ss must be unique for %ss %ss.' => '%ss mora da bude jedinstven za %ss %ss.',
        ],
        'other-context' => [
            '日本人は日本で話される言語です!' => [
                'singular',
                'plural1',
                'plural2',
            ],
        ],
    ],
];

@oscarotero oscarotero merged commit 3a9fdda into php-gettext:master Nov 6, 2023
5 checks passed
@oscarotero
Copy link
Member

Good idea. Thanks!

@mlocati mlocati deleted the prettier-array-generator branch November 6, 2023 17:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants