l10n '.arb' file format
Asked Answered
W

3

8

A project I came across has localization with follow structure

Each language has a directory under which there would be one file with same name as directory + '.arb' extension.

en/en.arb

I am not able to find a document that explains the format of this file. Sample content from the .arb file

"FOO_123": "Your pending cost is {COST}",
"@FOO_123": {
    "source_text": "Your pending cost is {COST}",
    "placeholders": {
       "COST": {
          "example": "$123.45",
          "description": "cost presented with currency symbol"
       }
    }

The closest one I could find is this.

  1. Is this authoritative document for understanding '.arb' files?

  2. What does a resource whose value has an anchor tag with a href look like? Is this correct way?

"FOO_124": "Refer to this {LINK}",
"@FOO_124": {
    "source_text": "Refer to this {LINK}",
    "placeholders": {
       "LINK": {
          "example": "<a href="https://en.wikipedia.org/">Encyclopedia</a>",
          "description": "Link to the Encyclopedia page"
       }
    }
Wainscoting answered 29/3, 2017 at 1:42 Comment(0)
D
17

ARB is google's format for localization, it is used in the web and in flutter framework

from ARB (Application Resource Bundle Specification)

Application Resource Bundle (abbr. ARB) is a localization resource format that is simple (based on JSON), extensible (vocabulary can be added without affecting existing tools and usage), and directly usable (applications can access the resource directly from this format without converting to another form).

In ARB, localizable resources are encoded as a JSON object. Each resource will have a resource entry identified by resource key, and an optional resource attribute entry with resource attribute key.

this answer is a summarization of my search and hopefully, it will save someones' time.

Duff answered 20/1, 2019 at 20:36 Comment(1)
An example would add to your answer.Hypethral
I
1

ARB stands for Application Resource Bundle.
It is actually a JSON file on steroids intended for localization, with .arb extension. Since it is based on JSON, it just defines standardized ways how to add more information around key-value pairs.

It is used for the web and flutter apps localization.

Note, the official ARB specification is generic, and may sometimes differ from localization library implementations.

Regarding translations with anchor tags within it, it again depends on the localization library implementation. Below is shown an example in Flutter.

ARB file example:

{
  ...
  "commonLink": "link",
  "@commonLink": {
    "description": "Link desc."
  },
  "commonReferContent": "Refer to this ",
  "@commonReferContent": {
    "description": "Refer content desc."
  }
  ...
}

Usage example:

...
RichText(
  text: TextSpan(children: [
    TextSpan(
      style: TextStyle(color: Colors.black),
      text: S.of(context).commonReferContent,
    ),
    TextSpan(
      style: TextStyle(
        color: Theme.of(context).primaryColor,
        decoration: TextDecoration.underline),
      text: S.of(context).commonLink,
      recognizer: TapGestureRecognizer()
        ..onTap = handleReferLinkTap),
  ]),
),
...

For more details about the ARB in Flutter, check out this article.

Inbred answered 14/7, 2020 at 12:17 Comment(0)
I
0

Just need to mention one thing that, in plain app_lang.arb Flutter l10n implementation description(@"yourKeyName": {}) is required, not optional. Alternate, recommended option is using Flutter Intl - Flutter localization binding from .arb files with official Intl library. It also nativly supports usng loclizotion without context. More details about Flutter i18n plugins is here.

Investment answered 4/12, 2022 at 12:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.