Git Product home page Git Product logo

intlc's People

Contributors

astlouisf avatar magellol avatar oliverjash avatar samhh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

intlc's Issues

MacOS releases

Since #38 we build a linux binary upon release. Should we also consider building one that'd work on mac os? Or should we expect mac os users to build it manually by pulling down the repo?

Avoid repeated JS instantiations

e.g. if the same number is used twice we'll compile two instantiations of Intl.NumberFormat. The compiler knows enough to potentially open a function body and declare a variable.

Union type unsafety when input referenced more than once

This applies to both string and number unions as produced by select and plural respectively.

When the same input is referenced twice, one for a union type and one potentially not, we produce different type-level output based upon the order. This happens because we check for type compatibility, but don't actually consider which type or subset of these types to preserve. For example, given {n, number} {n, plural, =1 {x}} we'll set the input to number, but the only safe input is actually the literal 1. If the interpolations are reversed we'll set the input to 1, but this still may not be safe if there are other interpolations referencing n later.

Additionally, it is possible for two unions to be incompatible if there are no overlapping members. An example is 1 | 2 and 3 | 4 for which there's no possible reconciliation. When two unions differ but there is at least one overlapping member, for example with 1 | 2 and 1 | 2 | 3, we should narrow the input to 1 | 2 - the overlapping members - to ensure that both matches can succeed.

For TypeScript, one cheap way to solve this may be to offload this entirely to the compiler via intersection operators. (1 | 2) & (1 | 2 | 3) resolves to 1 | 2, and zooming further out string & number resolves to never. This could potentially simplify the codebase by removing typechecking in intlc entirely.

CI

Test, lint, etc.

Prettified codegen

It's all on a single line at the moment. We'll probably run Prettier against it in web, but ideally the output would be more legible out of the box.

selectordinal condition/case mismatch

Minimal repro: {n, selectordinal, one {x} other {y}}

"ts" output:

export const f = (x: { n: number }) => string = x => `${(() => { switch (x.n) { case 'one': return `x`; default: return `y`; } })()}`

Escaping #

Should this be supported?

What should we do when we detect an unescaped hash outside of a plural?

Don't output JS/TS static strings

Some locales may legitimately not need a variable that others do, for example in the case of gender. When this happens, if there are no other interpolations, we're going to output incompatible types across locales:

export const en: (x: { gender: 'male' | 'female' }) => string = x => etc

export const es: string = etc

Functions and strings can't unionise (no such value), however functions/objects with omitted properties can. Specifically:

type Current
  = string
  | ((x: { gender: 'male' | 'female' }) => string)

// TypeScript will insist upon providing a full `x`
type Proposed
  = (() => string)
  | ((x: { gender: 'male' | 'female' }) => string)

Strictness of interpolation braces and tag brackets

At the moment, mostly randomly, we tolerate empty braces and interpolations with bad types, but not empty or otherwise faulty tags. We should decide upon a uniform approach, considering flexibility and (ease of checking) correctness. Escaping (#11) may be relevant here.

Ensure translation keys are valid

And then ensure they're not duplicates after any adjustments or made. Or filter out and potentially error on invalid keys. This should probably differ per-backend, or we could keep it very safe with alphanumerics.

Add --help

And then update the README. (It's going to be out of date as of #39.)

Rendering to multiple backends

At the moment you can specify an output "backend", but you might want multiple.

If/when we support multiple filetypes (we don't/wouldn't really yet as .ts is subsumed by .tsx) we can output multiple sibling files, but what about distinct backends for the same filetype?

Say, given "backends": ["ts", "tsx"], what should the output be? Because at present the export names would conflict.

Output with TSX missing React import

Needs ReactElement imported, and whatever best practices are now for bringing "React" and JSX sugar into scope. Let's not worry for now about other libraries/pragmas, that's tracked here: #33

We don't want to import this if we haven't used the "tsx" backend.

Going potentially further than this it's possible to use the aforementioned backend but still not require the imports, for example:

{
  "x": {
    "message": "y",
    "backend": "tsx"
  }
}
export const x: string = 'y'

A cheap and dirty way to do this would be to search the output string for ReactElement. A better way would be to use the AST to know with confidence whether or not this has happened. One way to know is, in the JavaScript compiler, if we've ever unwrapped a Lambda with a JSX InterpStrat - I think the dynamism of a lambda directly correlates to needing the import. Alternatively it may be cleaner to figure this out via the ICU Dataset as then the logic can be a single, simple predicate function that exists outside of the complexity of the compiler.

Whitespace

It's currently very strict (easiest/cheapest/laziest implementation path). Fairly easily changed where we want flexibility.

Preserve key order

Even more important now with flattening. This might mean moving away from Map (and its Ord constraint on its keys).

I kind of fell into alphabetical ordering as it was the easiest to implement, but probably fair to consider it a bug.

Plural case ordering

At the moment, for both plural and selectordinal, we allow "exact" (=0) and "rule" (zero) cases to be ordered in absolutely any way, and enforce that the wildcard (other), if any, comes at the end. This is arbitrary and can be changed to be more or less strict.

Accept locale input

Something, of some type, somehow - for example an additional function argument. Currently hardcoding en-US and otherwise not formatting strings and numbers.

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.