Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

l10n '.arb' file format

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"
       }
    }
like image 692
sam Avatar asked Mar 29 '17 01:03

sam


People also ask

What is arb file type?

The Application Resource Bundle (. arb) is a file format for localization based on JSON. The resource entries are encoded as JSON objects. Each object consists of a resource key with an optional attribute. ARB files are used for the localization of apps built with Google's Mobile App SDK called Flutter.

How do I open an ARB file?

How to open an ARB file. You can open and edit the data an ARB file contains in any text or source code editor, such as Microsoft Visual Studio Code (cross-platform) or GitHub Atom (cross-platform). To use an ARB file as an application resource bundle, you must install Dart (cross-platform) or Flutter (cross-platform).

What is ARB Flutter?

Written by Ilya. Flutter is an open-source UI software development kit by Google used to develop applications for Android, iOS, Linux, Mac, Windows, Google Fuchsia, and web from a single codebase.


2 Answers

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.

like image 173
humazed Avatar answered Oct 13 '22 15:10

humazed


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.

like image 40
Zoran Luledzija Avatar answered Oct 13 '22 14:10

Zoran Luledzija