Giter Club home page Giter Club logo

Comments (4)

marien-probesys avatar marien-probesys commented on August 26, 2024

I'm bringing this subject back to 0.2-dev and extending it.

I realize we can't translate strings based on a number. The old way was to use transchoice:

{{ '{0} No users|{1} 1 user|]1,Inf[ %count% users' | trans(users|length) }}

But transchoice no longer exists since Symfony 5! Two solutions:

  1. Use conditions in the template:
{% if users|length == 0 %}
    {{ 'No users' | trans }}
{% elseif users|length == 1 %}
    {{ '1 user' | trans }}
{% else %}
    {{ '%count% users' | trans({ '%choice%': users|length }) }}
{% endif %}
  1. use ICU format

The first solution is definitely not an option on the long term and makes things complicated.
The second solution looks better (ICU is the current supported format), but I had troubles the last time I tried.
Hopefully problems have been fixed since then.

The migration to ICU format should be done in four steps:

  • migrate files to +intl-icu.yaml
  • adapt current strings to use ICU format
  • change translation keys to use a keyword format (e.g. users.number) (ICU format is more verbose)
  • adapt the make i18n-extract script?

from bileto.

marien-probesys avatar marien-probesys commented on August 26, 2024

References:

from bileto.

marien-probesys avatar marien-probesys commented on August 26, 2024

I just migrated the translations to ICU format. It was painful because I wanted to use a keyword format for keys. At least it's done for the messages domain.

The validators domain is not fully migrated since the {{ value }} variables have to be renamed to { value } and there are a lot of strings. Instead, I'd like to remove all the unused keys (generated by Symfony) and only keep the ones that I explicitly use in Bileto. Btw, it seems that TranslatableMessage is optional for entity assertions messages (see https://symfony.com/doc/current/validation/translations.html), BUT the extract command was only able to find some keys when I tried 🤷

It would be the occasion to improve the error messages to be more assertive and explain what have to be done to fix the errors (e.g. "Choose a different email address since { value } is already used.")

from bileto.

marien-probesys avatar marien-probesys commented on August 26, 2024

I think I found a solution:

  1. change the domain of the actual "validators" and "security" (only https://github.com/Probesys/bileto/blob/main/src/Controller/BaseController.php#L33 is concerned) domains to "errors" (but keep the files for the default translations of Symfony)
  2. stop extracting messages for the "validators" and "security" domains
  3. extract the "errors" domain as it is done for "messages"

The only potential problem is that I don't know if the --domain argument of the extract command can take several domains. Otherwise, I'll have to extract "errors" and "messages" with two different commands :/

from bileto.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.