Last updated:
0 purchases
arb glue
ARB Glue #
ARB Glue is a tool that merges multiple files into one single ARB format file,
facilitating the management of internationalization resources.
Features:
YAML, which allows comment and multiple lines string;
Multiple files merge into one;
Set prefix on each file;
Nested structure;
Map structure on select and plural;
Placeholders are only needed in the base language.
This package operates independently from the project POS System.
Explore that repository to witness firsthand how this package is utilized within the online product.
Table of Contents:
Installation
Usage
Supported formats
Schema
Prefix
Nested Structure
Select and plural
Configuration
Installation #
Using pub.dev to manage the package:s
flutter pub add dev:arb_glue
copied to clipboard
Or add dependencies to pubspec.yaml:
dev_dependencies:
arb_glue: *
copied to clipboard
Usage #
Original Structure:
.
└── lib/
└── l10n/
├── en/
│ ├── global.yaml
│ └── feature-1.yaml
└── zh/
├── global.yaml
└── feature-1.yaml
copied to clipboard
Execution:
dart run arb_glue
# or
flutter pub run arb_glue
copied to clipboard
Resulting structure:
.
└── lib/
└── l10n/
├── en/
│ ├── global.yaml
│ └── feature-1.yaml
├── zh/
│ ├── global.yaml
│ └── feature-1.yaml
├── en.arb
└── zh.arb
copied to clipboard
Supported formats #
Currently, ARB Glue supports JSON and YAML encoded files.
In addition to ARB format, it allows writing descriptions directly into one key:
{
"myButton": "My Button {type}",
"@myButton": {
"description": "My custom button label",
"placeholders": {
"type": {"type": "String"}
}
}
}
copied to clipboard
This is equivalent to:
myButton: My Button
"@myButton":
description: My custom button label
placeholders:
type: {type: String}
copied to clipboard
And equal to:
myButton:
- My Button
# description and placeholders can switch position
- My custom button label
- type: {type: String}
copied to clipboard
Schema #
Flutter's localization (l10n) has several custom schemas,
which are elaborated upon in arb.schema.json.
If you're utilizing VSCode, streamline the schema setup by incorporating the following configuration:
{
"yaml.schemas": {
".vscode/arb.schema.json": ["/lib/l10n/**/*.yaml"]
}
}
copied to clipboard
Prefix #
Each file can have its own prefix by setting $prefix:
$prefix: myFeature
button: My Feature Button
copied to clipboard
This will render as:
{
"myFeatureButton": "My Feature Button"
}
copied to clipboard
Nested Structure #
arb_glue allow nested structure:
$prefix: myFeature
subModule: # this key is the default prefix value
$prefix: awesome # it can be customize by `$prefix`
button: My Awesome Button
copied to clipboard
This will render as:
{
"myFeatureAwesomeButton": "My Awesome Button"
}
copied to clipboard
Select and plural #
arb_glue can let you use map on select or plural text:
title:
- car: Car
bicycle: Bicycle
scooter: Scooter
other: UNKNOWN
- {tool: {type: String, mode: select}} # type and mode is not required, since they are using default values
# strictly equal to: `- {tool: {}}`
counter:
- =0: Empty
=1: One Item
other: '{count} Items'
- {count: {type: int, mode: plural}} # type and mode is required in this case
copied to clipboard
This will render as:
{
"title": "{tool, select, car{Car} bicycle{Bicycle} scooter{Scooter} other{UNKNOWN}}",
"@title": {
"placeholders": {
"tool": { "type": "String" }
}
},
"counter": "{count, plural, =0{Empty} =1{One Item} other{{count} Item}}",
"@counter": {
"placeholders": {
"count": { "type": "int" }
}
}
}
copied to clipboard
Configuration #
There are two methods to configure the process:
via pubspec.yaml or through command-line arguments.
pubspec.yaml:
# pubspec.yaml
name: MyApp
arb_glue:
source: lib/l10n
copied to clipboard
Command line:
dart run arb_glue --source lib/l10n
copied to clipboard
Full configuration options:
arb_glue:
# The source folder contains the files.
#
# Type: String
source: lib/l10n
# The destination folder where the files will be generated.
#
# Type: String
destination: lib/l10n
# Blacklisted folders inside the [source].
#
# Type: List<String>
exclude:
# The author of these messages.
#
# In the case of localized ARB files it can contain the names/details of the translator.
# see: https://github.com/google/app-resource-bundle/wiki/ApplicationResourceBundleSpecification#global-attributes
# Type: String
author:
# It describes (in text) the context in which all these resources apply.
#
# see: https://github.com/google/app-resource-bundle/wiki/ApplicationResourceBundleSpecification#global-attributes
# Type: String
context:
# Whether to add the last modified time of the file.
#
# Type: bool
lastModified: true
# The fallback values of the arb file.
#
# If not provided, the base locale will be the first locale found in the
# source folder.
#
# Based locale provide fallback placeholders to other locales.
#
# Type: String
base:
# The default value of other in select/plural mode.
#
# See example to get more detailed.
#
# Type: String
defaultOtherValue: UNKNOWN
# The file template for the output arb file.
#
# Type: String
fileTemplate: '{lang}.arb'
# Whether to print verbose output.
#
# Type: bool
verbose: false
copied to clipboard
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.