Git Product home page Git Product logo

elm-fluent's People

Stargazers

Jakob Schöttl avatar Rolf Kreibaum avatar Greg Edwards avatar Tad Lispy avatar David Dias avatar Eric Nething avatar Bangash avatar  avatar Nakaya avatar Hampus Gustavsson avatar Luke Plant avatar  avatar Zibi Braniecki avatar Stanisław Małolepszy avatar Rico Moorman avatar

Watchers

Luke Plant avatar  avatar James Cloos avatar

Forkers

rmoorman

elm-fluent's Issues

How should fallback work regarding number and date formatting?

If you use the --when-missing=fallback option, the generated code currently works as follows:

  • if a message is missing (detected at compile time), the message from the default language will be used instead.
  • this message will be passed the locale object that the developer passes in.

The result of this is that the output for that message could be a mixture of multiple locales.

For example, our default language is English, and in the French .ftl a message is missing. The end user has selected a French locale, and this Locale value gets passed to the dispatching translation function. The dispatching function calls the English message function (because there is no French function). But it still passes the original French locale value to that function.

So, for that message we will get English text. But if the message uses NUMBER() (explicitly or implicitly), the Intl.NumberFormat function gets passed the French locale, and will do French number formatting.

So, the message becomes a mixture of English and French, which is pretty confusing.

The alternative is that each generated module for a locale hard codes a Locale value into the module, and uses this for number/date formatting, instead of the passed in value (which means that we wouldn't actually need to pass in a Locale value to these functions.

This, however, is also confusing. We now have a mixture of number/date formatting within the page. Both alternatives have confusion - the current method means you get consistent number/date formatting across the page, although a message might have number/date formatting that is not consistent with the language it uses. The alternative means you get consistency within a message, but not consistent number/date formatting across the page.

There is another use case. If you have British English and American English locales, it could be useful to, say, have American English as the default, and only create British English messages where they are different - reducing the load on translators. In this case, the current behaviour is good - when British English locale is active, but American English messages are used, you still British number/date formatting. Similar things may be true for other locale 'dialects'.

Ideas welcome!

Suggestion: use intl-proxy to support Elm 0.19

Not really an issue, more of an suggestion, so feel free to close this if you do not like it.

I've recently implemented fluent compatability in my
own Elm i18n package on 0.19 using
the approach of decoding a proxy object at runtime. You can find the repo for the proxy here. The users overhead is pretty minimal in this approach:

  • import the proxy from the npm package in JS
  • pass the proxy as a flag to Elm
  • use the proxy in the generated code

What do you think?

Pontoon/l20n support

It would be nice to integrate support for Pontoon, which provides a GUI for translation that allows in-place editing.

For this to work best, I think the generated HTML would need to include the message ID - see the L20n docs .

<p data-l10n-id="about"></p>

In our case, we could generate the content of this tag as well, adding the data-l10n-id attribute just for the sake of Pontoon. I'm guessing this works only for content which is in the body of HTML nodes, rather than in attributes, for example.

(Note, a lot of Mozilla docs about Pontoon assuming you are using their infrastructure, pontoon.mozilla.org, but you can self-host).

More advanced methods for fallback

Currently only a single fallback language is supported. It would be nice to support things like "en-GB automatically falls back to en" etc. Ideas for how this should work are welcome (e.g. command line flags, automatic smart behaviour etc.). See also issue #9.

Add `ftl2elm --watch` option

When writing .ftl files, it is useful to have ftl2elm run automatically for various use cases.

This could be done by adding a --watch parameter to ftl2elm. Most likely watchdog will be the easiest way to do this.

As a workaround for now, you can us the watchmedo utility that watchdog provides:

$ pip install watchdog
$ watchmedo shell-command --recursive --patterns='*.ftl' --command 'ftl2elm --verbose --when-missing=fallback' locales

Better test coverage of run.py module and some others

There is currently poor test coverage for the compile_master function in elm_fluent/compiler.py and elm_fluent/run.py - especially for the error condition cases. We should fix this, it just requires a bit more setup - run.py is hard especially because its input is filesystem - one of the techniques here might help.

ftl2elm breaks with fluent 0.9+ installed

  • elm-fluent version: 0.2.0
  • Python version: 2.7.15rc1
  • Operating System: Ubuntu (WSL)

Description

The fluent dependency is listed as fluent>=0.8.0. pip install elm-fluent installs fluent 0.10.0, which breaks elm-fluent.

Both fluent 0.9.0 and 0.10.0 introduced changes to the AST. Please see the summary of the changes at https://github.com/projectfluent/python-fluent/releases. Notably, the VariantName node was removed. Variant keys can now be Numbers or Identifiers.

What I Did

(@elm) $ Mozilla/fluent/elm-example -> ftl2elm
Traceback (most recent call last):
  File "/c/Users/stas/Mozilla/fluent/@elm/bin/ftl2elm", line 7, in <module>
    from elm_fluent.cli import main
  File "/c/Users/stas/Mozilla/fluent/@elm/local/lib/python2.7/site-packages/elm_fluent/cli.py", line 13, in <module>
    from .run import ErrorWhenMissing, FallbackToDefaultLocaleWhenMissing, run_compile
  File "/c/Users/stas/Mozilla/fluent/@elm/local/lib/python2.7/site-packages/elm_fluent/run.py", line 10, in <module>
    from .compiler import (
  File "/c/Users/stas/Mozilla/fluent/@elm/local/lib/python2.7/site-packages/elm_fluent/compiler.py", line 987, in <module>
    @compile_expr.register(ast.VariantName)
AttributeError: 'module' object has no attribute 'VariantName'
(@elm) $ Mozilla/fluent/elm-example ->    

pip install fluent==0.8.0 fixed the issue.

Cross-file message and term references

Currently elm-fluent compiles each .ftl file separately. If you use a message reference or term references that refers to something in a different file, it will be a compilation error.

Fixing this requires a few things:

  • a stronger convention requiring message IDs to be unique across all FTL files. Otherwise we won't be able to know which message is being referred to in the case of duplicates. Alternatively, we only enforce the uniqueness across files if we have a message reference that would be ambiguous otherwise.

  • a change to ftl2elm so that it can find references across files. We will likely need to do a couple of passes, first to find all the message/terms names then to compile.

  • a change to the compiler so that for messages it can import the compiled messages from other modules. If FTL files have cyclic dependencies, this won't work however, so perhaps it will be better to inline all messages references that cross modules.

  • for terms, it is less complex, because these are always inlined so importing is definitely not necessary.

Possibly change the order of message function arguments?

Currently the function signature is:

Locale.Locale -> a -> String

or:

Locale.Locale -> a -> List (String, List (Html.Attribute msg)) -> List (Html.Html msg)

If we put Locale as the last argument, instead of the first, would it be more useful? By supplying the message arguments (and attributes for the Html case), but omitting the Locale, you would then have something that represented an untranslated message, which might crop up quite a bit in actual usage.

Should use escape sequences for some unicode chars

The generated Elm code embeds all unicode characters directly into strings. It would probably be better if some were represented using escape sequences - particularly non-printable ones, such as the BDI control characters. The current compiler output can have things like this:

String.concat [ "⁨"
              , args_.user_name
              , "⁩ napisał:"
              ]

Here there are BDI chars in the first and last string literal, but that isn't visible at all, and the first string looks like a useless empty string. This could be an issue when debugging.

Do not include unused modules in generated code

Otherwise we get warning from elm-make etc, and it is just cleaner.

This will involve Module objects searching over their contained expressions to see which imported modules are actually used.

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.