{"id":15674907,"url":"https://github.com/eemeli/fluent-compiler","last_synced_at":"2025-05-06T23:40:24.157Z","repository":{"id":34915566,"uuid":"182593061","full_name":"eemeli/fluent-compiler","owner":"eemeli","description":"JavaScript transpiler for Fluent messages","archived":false,"fork":false,"pushed_at":"2023-01-03T20:17:09.000Z","size":2682,"stargazers_count":14,"open_issues_count":22,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-04T21:12:01.799Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eemeli.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-04-21T23:36:04.000Z","updated_at":"2022-08-17T08:03:43.000Z","dependencies_parsed_at":"2023-01-15T10:20:27.798Z","dependency_job_id":null,"html_url":"https://github.com/eemeli/fluent-compiler","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eemeli%2Ffluent-compiler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eemeli%2Ffluent-compiler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eemeli%2Ffluent-compiler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eemeli%2Ffluent-compiler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eemeli","download_url":"https://codeload.github.com/eemeli/fluent-compiler/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252788376,"owners_count":21804280,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-03T15:52:56.344Z","updated_at":"2025-05-06T23:40:24.112Z","avatar_url":"https://github.com/eemeli.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# fluent-compiler\n\n`fluent-compiler` provides a JavaScript stringifier for [Fluent]. Essentially,\nit's a transpiler that allows converting files from Fluent's `ftl` format to\nJavaScript, outputting an ES6 module that exports a [FluentBundle][bundle].\n\nThe difference between this package and the core `fluent` package is that the\nlatter will need to compile your messages on the client, and is about 10kB when\ncompressed. The runtime component of `fluent-compiler` is about 1.2kB, and it\nlets you take care of the message compilation during your build.\n\n**NOTE:** The current runtime implements the `format()/compound()` API of\nFluent.js [PR #360], which is likely still to get revised.\n\n[fluent]: https://projectfluent.org/\n[bundle]: http://projectfluent.org/fluent.js/fluent/class/src/bundle.js~FluentBundle.html\n[resource]: http://projectfluent.org/fluent.js/fluent/class/src/resource.js~FluentResource.html\n[pr #360]: https://github.com/projectfluent/fluent.js/pull/360\n\n## API\n\n```js\nimport { compile } from 'fluent-compiler'\n```\n\n### `compile(locales, source, options = {}) =\u003e string`\n\n| Param   | Type                            | Description                                                                        |\n| ------- | ------------------------------- | ---------------------------------------------------------------------------------- |\n| locales | `string | string[] | undefined` | The resource's locale identifier                                                   |\n| source  | `string | Resource`             | Fluent source as a string, or an AST compiled with the [`fluent-syntax`][1] parser |\n| options | `CompilerOptions`               | Compiler options object (optional)                                                 |\n\n#### `CompilerOptions`\n\n| Option         | Type       | Default                     | Description                                                   |\n| -------------- | ---------- | --------------------------- | ------------------------------------------------------------- |\n| runtime        | `string`   | `'bundle'`                  | The type of runtime to use; either `'bundle'` or `'resource'` |\n| runtimeGlobals | `string[]` | `['DATETIME', 'NUMBER']`    | Identifiers of global functions available in the runtime      |\n| runtimePath    | `string`   | `'fluent-compiler/runtime'` | Path for the runtime dependency                               |\n| useIsolating   | `boolean`  | `true`                      | Wrap placeables with Unicode FSI \u0026 PDI isolation marks        |\n| withJunk       | `boolean`  | `false`                     | Include unparsed source as comments in the output             |\n\n[1]: https://www.npmjs.com/package/fluent-syntax\n\nThe string returned by `compile()` is the string representation of an ES6 module, which in turn exports either the [bundle] or [resource] interfaces for the source messages. Note that the `bundle.addMessages()` is not included, as it requires message compilation; use `bundle.addResource()` instead:\n\n```js\nimport bundle from './default_messages'\nimport { resource } from './extra_messages'\n\nbundle.addResource(resource, { allowOverrides: true })\n// bundle now includes all default_messages as well as extra_messages,\n// with the latter overriding the former\n```\n\n## Usage\n\nFluent source file `messages.it.ftl`:\n\n```ftl\n-sync-brand-name = {$capitalization -\u003e\n   *[uppercase] Account Firefox\n    [lowercase] account Firefox\n}\n\nsync-dialog-title = {-sync-brand-name}\nsync-headline-title =\n    {-sync-brand-name}: il modo migliore\n    per avere i tuoi dati sempre con te\n\n# Explicitly request the lowercase variant of the brand name.\nsync-signedout-account-title =\n    Connetti il tuo {-sync-brand-name(capitalization: \"lowercase\")}\n```\n\nBuild script:\n\n```js\nimport { compile } from 'fluent-compiler'\nimport fs from 'fs'\n\nconst src = fs.readFileSync('messages.it.ftl')\nconst js = compile('it', src)\nfs.writeFileSync('messages.it.js', js)\n```\n\nApplication code:\n\n```js\nimport it from './messages.it'\n\nit.format('sync-signedout-account-title')\n// 'Connetti il tuo account Firefox'\n```\n\n## Polyfills\n\nThe ES6 module output by `compile()` will probably need to itself be transpiled,\nas it uses Object Spread syntax (currently at Stage 3). Furthermore, the runtime\nmay need polyfills for the Intl objects and Object.entries (used by the bundle's\n`messages` getter). In particular, [intl-pluralrules] patches some of the\ndeficiencies in current browsers.\n\n[intl-pluralrules]: https://www.npmjs.com/package/intl-pluralrules\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feemeli%2Ffluent-compiler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feemeli%2Ffluent-compiler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feemeli%2Ffluent-compiler/lists"}