i18n-message_format 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.envrc +10 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +132 -0
- data/LICENSE.txt +21 -0
- data/README.md +105 -0
- data/Rakefile +12 -0
- data/devenv.lock +123 -0
- data/devenv.nix +57 -0
- data/devenv.yaml +15 -0
- data/docs/plans/2026-02-25-icu-message-format-design.md +141 -0
- data/docs/plans/2026-02-25-icu-message-format-plan.md +1947 -0
- data/lib/i18n/message_format/backend.rb +172 -0
- data/lib/i18n/message_format/cache.rb +75 -0
- data/lib/i18n/message_format/formatter.rb +179 -0
- data/lib/i18n/message_format/nodes.rb +96 -0
- data/lib/i18n/message_format/ordinal_rules.rb +64 -0
- data/lib/i18n/message_format/parser.rb +328 -0
- data/lib/i18n/message_format/version.rb +8 -0
- data/lib/i18n/message_format.rb +74 -0
- data/sig/i18n/message_format.rbs +6 -0
- metadata +78 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 5ba2dc552b6ed476c92dc2eb3e79643d1820e0b9ac3648efabceecbc2205700a
|
|
4
|
+
data.tar.gz: ac841cf20af045dbfa54619a8f37181e8770e2a1667c2401a3c9431bb1bc8980
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: d4b201b2ab2f751d15d29c7bf4b57e905b13aead055912d02d6219e7f7b342f86e8543f7b68b874730f237f23b4c6767787feab981741d43f1c8aa27738d3d98
|
|
7
|
+
data.tar.gz: 3ba0a787f483e48c5c3843705a62065b7b8416351a12c15a7241b717f81cd3d3184cb6aabda4b05869954a852420a49a70847764a0414a5fc6eab2e46c0714cf
|
data/.envrc
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export DIRENV_WARN_TIMEOUT=20s
|
|
2
|
+
|
|
3
|
+
eval "$(devenv direnvrc)"
|
|
4
|
+
|
|
5
|
+
# `use devenv` supports the same options as the `devenv shell` command.
|
|
6
|
+
#
|
|
7
|
+
# To silence the output, use `--quiet`.
|
|
8
|
+
#
|
|
9
|
+
# Example usage: use devenv --quiet --impure --option services.postgres.enable:bool true
|
|
10
|
+
use devenv
|
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our
|
|
6
|
+
community a harassment-free experience for everyone, regardless of age, body
|
|
7
|
+
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
|
8
|
+
identity and expression, level of experience, education, socio-economic status,
|
|
9
|
+
nationality, personal appearance, race, caste, color, religion, or sexual
|
|
10
|
+
identity and orientation.
|
|
11
|
+
|
|
12
|
+
We pledge to act and interact in ways that contribute to an open, welcoming,
|
|
13
|
+
diverse, inclusive, and healthy community.
|
|
14
|
+
|
|
15
|
+
## Our Standards
|
|
16
|
+
|
|
17
|
+
Examples of behavior that contributes to a positive environment for our
|
|
18
|
+
community include:
|
|
19
|
+
|
|
20
|
+
* Demonstrating empathy and kindness toward other people
|
|
21
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
|
22
|
+
* Giving and gracefully accepting constructive feedback
|
|
23
|
+
* Accepting responsibility and apologizing to those affected by our mistakes,
|
|
24
|
+
and learning from the experience
|
|
25
|
+
* Focusing on what is best not just for us as individuals, but for the overall
|
|
26
|
+
community
|
|
27
|
+
|
|
28
|
+
Examples of unacceptable behavior include:
|
|
29
|
+
|
|
30
|
+
* The use of sexualized language or imagery, and sexual attention or advances of
|
|
31
|
+
any kind
|
|
32
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
|
33
|
+
* Public or private harassment
|
|
34
|
+
* Publishing others' private information, such as a physical or email address,
|
|
35
|
+
without their explicit permission
|
|
36
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
|
37
|
+
professional setting
|
|
38
|
+
|
|
39
|
+
## Enforcement Responsibilities
|
|
40
|
+
|
|
41
|
+
Community leaders are responsible for clarifying and enforcing our standards of
|
|
42
|
+
acceptable behavior and will take appropriate and fair corrective action in
|
|
43
|
+
response to any behavior that they deem inappropriate, threatening, offensive,
|
|
44
|
+
or harmful.
|
|
45
|
+
|
|
46
|
+
Community leaders have the right and responsibility to remove, edit, or reject
|
|
47
|
+
comments, commits, code, wiki edits, issues, and other contributions that are
|
|
48
|
+
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
|
49
|
+
decisions when appropriate.
|
|
50
|
+
|
|
51
|
+
## Scope
|
|
52
|
+
|
|
53
|
+
This Code of Conduct applies within all community spaces, and also applies when
|
|
54
|
+
an individual is officially representing the community in public spaces.
|
|
55
|
+
Examples of representing our community include using an official email address,
|
|
56
|
+
posting via an official social media account, or acting as an appointed
|
|
57
|
+
representative at an online or offline event.
|
|
58
|
+
|
|
59
|
+
## Enforcement
|
|
60
|
+
|
|
61
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
62
|
+
reported to the community leaders responsible for enforcement at
|
|
63
|
+
[INSERT CONTACT METHOD].
|
|
64
|
+
All complaints will be reviewed and investigated promptly and fairly.
|
|
65
|
+
|
|
66
|
+
All community leaders are obligated to respect the privacy and security of the
|
|
67
|
+
reporter of any incident.
|
|
68
|
+
|
|
69
|
+
## Enforcement Guidelines
|
|
70
|
+
|
|
71
|
+
Community leaders will follow these Community Impact Guidelines in determining
|
|
72
|
+
the consequences for any action they deem in violation of this Code of Conduct:
|
|
73
|
+
|
|
74
|
+
### 1. Correction
|
|
75
|
+
|
|
76
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed
|
|
77
|
+
unprofessional or unwelcome in the community.
|
|
78
|
+
|
|
79
|
+
**Consequence**: A private, written warning from community leaders, providing
|
|
80
|
+
clarity around the nature of the violation and an explanation of why the
|
|
81
|
+
behavior was inappropriate. A public apology may be requested.
|
|
82
|
+
|
|
83
|
+
### 2. Warning
|
|
84
|
+
|
|
85
|
+
**Community Impact**: A violation through a single incident or series of
|
|
86
|
+
actions.
|
|
87
|
+
|
|
88
|
+
**Consequence**: A warning with consequences for continued behavior. No
|
|
89
|
+
interaction with the people involved, including unsolicited interaction with
|
|
90
|
+
those enforcing the Code of Conduct, for a specified period of time. This
|
|
91
|
+
includes avoiding interactions in community spaces as well as external channels
|
|
92
|
+
like social media. Violating these terms may lead to a temporary or permanent
|
|
93
|
+
ban.
|
|
94
|
+
|
|
95
|
+
### 3. Temporary Ban
|
|
96
|
+
|
|
97
|
+
**Community Impact**: A serious violation of community standards, including
|
|
98
|
+
sustained inappropriate behavior.
|
|
99
|
+
|
|
100
|
+
**Consequence**: A temporary ban from any sort of interaction or public
|
|
101
|
+
communication with the community for a specified period of time. No public or
|
|
102
|
+
private interaction with the people involved, including unsolicited interaction
|
|
103
|
+
with those enforcing the Code of Conduct, is allowed during this period.
|
|
104
|
+
Violating these terms may lead to a permanent ban.
|
|
105
|
+
|
|
106
|
+
### 4. Permanent Ban
|
|
107
|
+
|
|
108
|
+
**Community Impact**: Demonstrating a pattern of violation of community
|
|
109
|
+
standards, including sustained inappropriate behavior, harassment of an
|
|
110
|
+
individual, or aggression toward or disparagement of classes of individuals.
|
|
111
|
+
|
|
112
|
+
**Consequence**: A permanent ban from any sort of public interaction within the
|
|
113
|
+
community.
|
|
114
|
+
|
|
115
|
+
## Attribution
|
|
116
|
+
|
|
117
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
|
118
|
+
version 2.1, available at
|
|
119
|
+
[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
|
|
120
|
+
|
|
121
|
+
Community Impact Guidelines were inspired by
|
|
122
|
+
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].
|
|
123
|
+
|
|
124
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
|
125
|
+
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
|
|
126
|
+
[https://www.contributor-covenant.org/translations][translations].
|
|
127
|
+
|
|
128
|
+
[homepage]: https://www.contributor-covenant.org
|
|
129
|
+
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
|
|
130
|
+
[Mozilla CoC]: https://github.com/mozilla/diversity
|
|
131
|
+
[FAQ]: https://www.contributor-covenant.org/faq
|
|
132
|
+
[translations]: https://www.contributor-covenant.org/translations
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Chris Fung
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# I18n::MessageFormat
|
|
2
|
+
|
|
3
|
+
ICU Message Format support for the Ruby [i18n](https://github.com/ruby-i18n/i18n) gem. Pure Ruby parser, no native dependencies.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
bundle add i18n-message_format
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
### Standalone
|
|
14
|
+
|
|
15
|
+
```ruby
|
|
16
|
+
require "i18n/message_format"
|
|
17
|
+
|
|
18
|
+
I18n::MessageFormat.format(
|
|
19
|
+
"{name} has {count, plural, one {# item} other {# items}}",
|
|
20
|
+
name: "Alice", count: 3
|
|
21
|
+
)
|
|
22
|
+
# => "Alice has 3 items"
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### With I18n Backend
|
|
26
|
+
|
|
27
|
+
Store your Message Format strings in separate YAML files:
|
|
28
|
+
|
|
29
|
+
```yaml
|
|
30
|
+
# config/locales/mf/en.yml
|
|
31
|
+
en:
|
|
32
|
+
greeting: "Hello {name}!"
|
|
33
|
+
items: "{count, plural, one {# item} other {# items}}"
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Configure the backend:
|
|
37
|
+
|
|
38
|
+
```ruby
|
|
39
|
+
I18n.backend = I18n::Backend::Chain.new(
|
|
40
|
+
I18n::MessageFormat::Backend.new("config/locales/mf/*.yml"),
|
|
41
|
+
I18n::Backend::Simple.new
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
I18n.t("greeting", name: "Alice")
|
|
45
|
+
# => "Hello Alice!"
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Supported Syntax
|
|
49
|
+
|
|
50
|
+
- Simple arguments: `{name}`
|
|
51
|
+
- Number format: `{count, number}`
|
|
52
|
+
- Date format: `{d, date, short}`
|
|
53
|
+
- Time format: `{t, time, short}`
|
|
54
|
+
- Plural: `{count, plural, one {# item} other {# items}}`
|
|
55
|
+
- Select: `{gender, select, male {He} female {She} other {They}}`
|
|
56
|
+
- Selectordinal: `{pos, selectordinal, one {#st} two {#nd} few {#rd} other {#th}}`
|
|
57
|
+
- Nested messages
|
|
58
|
+
- Escaped braces: `'{ '} ''`
|
|
59
|
+
|
|
60
|
+
### Number, Date, and Time Formatting
|
|
61
|
+
|
|
62
|
+
Number, date, and time format arguments delegate to [`I18n.localize`](https://www.rubydoc.info/gems/i18n/I18n/Backend/Base#localize-instance_method), so their output depends on the format definitions in your I18n backend.
|
|
63
|
+
|
|
64
|
+
- **Number** — `{count, number}` calls `I18n.localize` with the value and locale. The optional style (e.g. `{count, number, integer}`) is passed as the `:format` option.
|
|
65
|
+
- **Date** — `{d, date, short}` calls `I18n.localize` with `:format => :short`. The style maps directly to an I18n date format key. Common styles are `short`, `medium`, `long`, and `full`, but any key defined under `date.formats` in your locale file works.
|
|
66
|
+
- **Time** — `{t, time, short}` works the same way, looking up keys under `time.formats`.
|
|
67
|
+
|
|
68
|
+
For example, with these locale definitions:
|
|
69
|
+
|
|
70
|
+
```yaml
|
|
71
|
+
en:
|
|
72
|
+
date:
|
|
73
|
+
formats:
|
|
74
|
+
short: "%b %-d"
|
|
75
|
+
long: "%B %-d, %Y"
|
|
76
|
+
time:
|
|
77
|
+
formats:
|
|
78
|
+
short: "%H:%M"
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
The pattern `"Updated on {d, date, short}"` with `d: Date.new(2026, 1, 15)` produces `"Updated on Jan 15"`.
|
|
82
|
+
|
|
83
|
+
### Plural Rules
|
|
84
|
+
|
|
85
|
+
Plural rules are also delegated to the I18n backend. Any gem which supplies plural rules to I18n will work with `I18n::MessageFormat`, e.g. [`rails-i18n`](https://github.com/svenfuchs/rails-i18n).
|
|
86
|
+
|
|
87
|
+
### Ordinal Rules
|
|
88
|
+
|
|
89
|
+
Install built-in ordinal rules for selectordinal support:
|
|
90
|
+
|
|
91
|
+
```ruby
|
|
92
|
+
I18n::MessageFormat::OrdinalRules.install(:en)
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Development
|
|
96
|
+
|
|
97
|
+
After checking out the repo, run `bin/setup` to install dependencies. Run tests with `bundle exec rake test`.
|
|
98
|
+
|
|
99
|
+
## Contributing
|
|
100
|
+
|
|
101
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/aergonaut/i18n-message_format. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/aergonaut/i18n-message_format/blob/main/CODE_OF_CONDUCT.md).
|
|
102
|
+
|
|
103
|
+
## License
|
|
104
|
+
|
|
105
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/devenv.lock
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
{
|
|
2
|
+
"nodes": {
|
|
3
|
+
"devenv": {
|
|
4
|
+
"locked": {
|
|
5
|
+
"dir": "src/modules",
|
|
6
|
+
"lastModified": 1770744655,
|
|
7
|
+
"owner": "cachix",
|
|
8
|
+
"repo": "devenv",
|
|
9
|
+
"rev": "d8bd7b74d0604227220074ac0bc934c4efb2b8fb",
|
|
10
|
+
"type": "github"
|
|
11
|
+
},
|
|
12
|
+
"original": {
|
|
13
|
+
"dir": "src/modules",
|
|
14
|
+
"owner": "cachix",
|
|
15
|
+
"repo": "devenv",
|
|
16
|
+
"type": "github"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"flake-compat": {
|
|
20
|
+
"flake": false,
|
|
21
|
+
"locked": {
|
|
22
|
+
"lastModified": 1767039857,
|
|
23
|
+
"owner": "NixOS",
|
|
24
|
+
"repo": "flake-compat",
|
|
25
|
+
"rev": "5edf11c44bc78a0d334f6334cdaf7d60d732daab",
|
|
26
|
+
"type": "github"
|
|
27
|
+
},
|
|
28
|
+
"original": {
|
|
29
|
+
"owner": "NixOS",
|
|
30
|
+
"repo": "flake-compat",
|
|
31
|
+
"type": "github"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"git-hooks": {
|
|
35
|
+
"inputs": {
|
|
36
|
+
"flake-compat": "flake-compat",
|
|
37
|
+
"gitignore": "gitignore",
|
|
38
|
+
"nixpkgs": [
|
|
39
|
+
"nixpkgs"
|
|
40
|
+
]
|
|
41
|
+
},
|
|
42
|
+
"locked": {
|
|
43
|
+
"lastModified": 1770726378,
|
|
44
|
+
"owner": "cachix",
|
|
45
|
+
"repo": "git-hooks.nix",
|
|
46
|
+
"rev": "5eaaedde414f6eb1aea8b8525c466dc37bba95ae",
|
|
47
|
+
"type": "github"
|
|
48
|
+
},
|
|
49
|
+
"original": {
|
|
50
|
+
"owner": "cachix",
|
|
51
|
+
"repo": "git-hooks.nix",
|
|
52
|
+
"type": "github"
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
"gitignore": {
|
|
56
|
+
"inputs": {
|
|
57
|
+
"nixpkgs": [
|
|
58
|
+
"git-hooks",
|
|
59
|
+
"nixpkgs"
|
|
60
|
+
]
|
|
61
|
+
},
|
|
62
|
+
"locked": {
|
|
63
|
+
"lastModified": 1762808025,
|
|
64
|
+
"owner": "hercules-ci",
|
|
65
|
+
"repo": "gitignore.nix",
|
|
66
|
+
"rev": "cb5e3fdca1de58ccbc3ef53de65bd372b48f567c",
|
|
67
|
+
"type": "github"
|
|
68
|
+
},
|
|
69
|
+
"original": {
|
|
70
|
+
"owner": "hercules-ci",
|
|
71
|
+
"repo": "gitignore.nix",
|
|
72
|
+
"type": "github"
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
"nixpkgs": {
|
|
76
|
+
"inputs": {
|
|
77
|
+
"nixpkgs-src": "nixpkgs-src"
|
|
78
|
+
},
|
|
79
|
+
"locked": {
|
|
80
|
+
"lastModified": 1770434727,
|
|
81
|
+
"owner": "cachix",
|
|
82
|
+
"repo": "devenv-nixpkgs",
|
|
83
|
+
"rev": "8430f16a39c27bdeef236f1eeb56f0b51b33d348",
|
|
84
|
+
"type": "github"
|
|
85
|
+
},
|
|
86
|
+
"original": {
|
|
87
|
+
"owner": "cachix",
|
|
88
|
+
"ref": "rolling",
|
|
89
|
+
"repo": "devenv-nixpkgs",
|
|
90
|
+
"type": "github"
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
"nixpkgs-src": {
|
|
94
|
+
"flake": false,
|
|
95
|
+
"locked": {
|
|
96
|
+
"lastModified": 1769922788,
|
|
97
|
+
"narHash": "sha256-H3AfG4ObMDTkTJYkd8cz1/RbY9LatN5Mk4UF48VuSXc=",
|
|
98
|
+
"owner": "NixOS",
|
|
99
|
+
"repo": "nixpkgs",
|
|
100
|
+
"rev": "207d15f1a6603226e1e223dc79ac29c7846da32e",
|
|
101
|
+
"type": "github"
|
|
102
|
+
},
|
|
103
|
+
"original": {
|
|
104
|
+
"owner": "NixOS",
|
|
105
|
+
"ref": "nixpkgs-unstable",
|
|
106
|
+
"repo": "nixpkgs",
|
|
107
|
+
"type": "github"
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
"root": {
|
|
111
|
+
"inputs": {
|
|
112
|
+
"devenv": "devenv",
|
|
113
|
+
"git-hooks": "git-hooks",
|
|
114
|
+
"nixpkgs": "nixpkgs",
|
|
115
|
+
"pre-commit-hooks": [
|
|
116
|
+
"git-hooks"
|
|
117
|
+
]
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
"root": "root",
|
|
122
|
+
"version": 7
|
|
123
|
+
}
|
data/devenv.nix
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{ pkgs, lib, config, inputs, ... }:
|
|
2
|
+
|
|
3
|
+
{
|
|
4
|
+
# https://devenv.sh/basics/
|
|
5
|
+
env.GREET = "devenv";
|
|
6
|
+
|
|
7
|
+
# https://devenv.sh/packages/
|
|
8
|
+
packages = with pkgs; [
|
|
9
|
+
git
|
|
10
|
+
openssl
|
|
11
|
+
libyaml
|
|
12
|
+
postgresql
|
|
13
|
+
git
|
|
14
|
+
curl
|
|
15
|
+
redis
|
|
16
|
+
nixd
|
|
17
|
+
nixfmt-rfc-style
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
# https://devenv.sh/languages/
|
|
21
|
+
# languages.rust.enable = true;
|
|
22
|
+
|
|
23
|
+
languages.ruby.enable = true;
|
|
24
|
+
|
|
25
|
+
# https://devenv.sh/processes/
|
|
26
|
+
# processes.cargo-watch.exec = "cargo-watch";
|
|
27
|
+
|
|
28
|
+
# https://devenv.sh/services/
|
|
29
|
+
# services.postgres.enable = true;
|
|
30
|
+
|
|
31
|
+
# https://devenv.sh/scripts/
|
|
32
|
+
scripts.hello.exec = ''
|
|
33
|
+
echo hello from $GREET
|
|
34
|
+
'';
|
|
35
|
+
|
|
36
|
+
enterShell = ''
|
|
37
|
+
hello
|
|
38
|
+
git --version
|
|
39
|
+
'';
|
|
40
|
+
|
|
41
|
+
# https://devenv.sh/tasks/
|
|
42
|
+
# tasks = {
|
|
43
|
+
# "myproj:setup".exec = "mytool build";
|
|
44
|
+
# "devenv:enterShell".after = [ "myproj:setup" ];
|
|
45
|
+
# };
|
|
46
|
+
|
|
47
|
+
# https://devenv.sh/tests/
|
|
48
|
+
enterTest = ''
|
|
49
|
+
echo "Running tests"
|
|
50
|
+
git --version | grep --color=auto "${pkgs.git.version}"
|
|
51
|
+
'';
|
|
52
|
+
|
|
53
|
+
# https://devenv.sh/git-hooks/
|
|
54
|
+
# git-hooks.hooks.shellcheck.enable = true;
|
|
55
|
+
|
|
56
|
+
# See full reference at https://devenv.sh/reference/options/
|
|
57
|
+
}
|
data/devenv.yaml
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# yaml-language-server: $schema=https://devenv.sh/devenv.schema.json
|
|
2
|
+
inputs:
|
|
3
|
+
nixpkgs:
|
|
4
|
+
url: github:cachix/devenv-nixpkgs/rolling
|
|
5
|
+
|
|
6
|
+
# If you're using non-OSS software, you can set allowUnfree to true.
|
|
7
|
+
# allowUnfree: true
|
|
8
|
+
|
|
9
|
+
# If you're willing to use a package that's vulnerable
|
|
10
|
+
# permittedInsecurePackages:
|
|
11
|
+
# - "openssl-1.1.1w"
|
|
12
|
+
|
|
13
|
+
# If you have more than one devenv you can merge them
|
|
14
|
+
#imports:
|
|
15
|
+
# - ./backend
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
# ICU Message Format for Ruby i18n — Design
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
`i18n-message_format` is a Ruby gem that adds ICU Message Format support to the
|
|
6
|
+
`i18n` gem. It provides a pure Ruby parser, a formatter integrated with existing
|
|
7
|
+
i18n infrastructure, and a chainable backend for seamless use alongside standard
|
|
8
|
+
translation files.
|
|
9
|
+
|
|
10
|
+
## Architecture
|
|
11
|
+
|
|
12
|
+
```
|
|
13
|
+
YAML files --> Backend (load + lookup) --> Parser (string -> AST) --> Formatter (AST + args -> string)
|
|
14
|
+
|
|
|
15
|
+
LRU Cache (pattern -> AST)
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Three layers:
|
|
19
|
+
|
|
20
|
+
1. **Parser** — recursive descent parser, string to AST
|
|
21
|
+
2. **Formatter** — AST walker, resolves arguments to produce output
|
|
22
|
+
3. **Backend** — `I18n::Backend::Base` implementation for use with `I18n::Backend::Chain`
|
|
23
|
+
|
|
24
|
+
## Parser
|
|
25
|
+
|
|
26
|
+
Pure Ruby recursive descent parser supporting the full ICU Message Format spec:
|
|
27
|
+
|
|
28
|
+
- Literal text
|
|
29
|
+
- Simple arguments: `{name}`
|
|
30
|
+
- Formatted arguments: `{count, number}`, `{date, date, short}`
|
|
31
|
+
- Plural: `{count, plural, one {# item} other {# items}}`
|
|
32
|
+
- Select: `{gender, select, male {He} female {She} other {They}}`
|
|
33
|
+
- Selectordinal: `{position, selectordinal, one {#st} two {#nd} few {#rd} other {#th}}`
|
|
34
|
+
- Nested messages (full recursive nesting)
|
|
35
|
+
- Escaped braces: `'{` `'}` `''`
|
|
36
|
+
|
|
37
|
+
### AST Node Types
|
|
38
|
+
|
|
39
|
+
- `TextNode` — literal text
|
|
40
|
+
- `ArgumentNode` — simple argument reference
|
|
41
|
+
- `PluralNode` — plural selection
|
|
42
|
+
- `SelectNode` — value-based selection
|
|
43
|
+
- `SelectOrdinalNode` — ordinal plural selection
|
|
44
|
+
- `NumberFormatNode` — number formatting
|
|
45
|
+
- `DateFormatNode` — date formatting
|
|
46
|
+
- `TimeFormatNode` — time formatting
|
|
47
|
+
|
|
48
|
+
## Formatter
|
|
49
|
+
|
|
50
|
+
Walks the AST and resolves each node:
|
|
51
|
+
|
|
52
|
+
- **TextNode** — returns literal string
|
|
53
|
+
- **ArgumentNode** — looks up named argument, calls `to_s`
|
|
54
|
+
- **PluralNode** — uses i18n gem's plural rules (`i18n.plural.rule`) to pick the
|
|
55
|
+
correct branch. Handles exact matches (`=0`, `=1`). Replaces `#` with the
|
|
56
|
+
numeric value.
|
|
57
|
+
- **SelectNode** — matches argument value against branches, falls back to `other`
|
|
58
|
+
- **SelectOrdinalNode** — uses ordinal plural rules (`i18n.ordinal.rule`
|
|
59
|
+
convention, see below)
|
|
60
|
+
- **NumberFormatNode** — formats via `I18n.l` / i18n number formatting
|
|
61
|
+
- **DateFormatNode / TimeFormatNode** — formats via `I18n.l(value, format: style)`
|
|
62
|
+
|
|
63
|
+
## Plural Rules
|
|
64
|
+
|
|
65
|
+
### Cardinal (plural)
|
|
66
|
+
|
|
67
|
+
Delegates to the i18n gem's existing pluralization infrastructure:
|
|
68
|
+
|
|
69
|
+
- Looks up `i18n.plural.rule` in locale data (returns a lambda: count -> category)
|
|
70
|
+
- Compatible with `rails-i18n` and other gems that ship pluralization rules
|
|
71
|
+
- Falls back to English rules (1 = `:one`, else `:other`) when no rule is found
|
|
72
|
+
|
|
73
|
+
### Ordinal (selectordinal)
|
|
74
|
+
|
|
75
|
+
The i18n gem has no built-in ordinal convention. This gem defines one:
|
|
76
|
+
|
|
77
|
+
- Convention: `i18n.ordinal.rule` in locale data (same lambda pattern)
|
|
78
|
+
- Ships built-in ordinal rules for common locales (English, etc.)
|
|
79
|
+
- Users or other gems can register additional ordinal rules
|
|
80
|
+
|
|
81
|
+
## Backend
|
|
82
|
+
|
|
83
|
+
`I18n::MessageFormat::Backend` implements `I18n::Backend::Base`.
|
|
84
|
+
|
|
85
|
+
```ruby
|
|
86
|
+
I18n.backend = I18n::Backend::Chain.new(
|
|
87
|
+
I18n::MessageFormat::Backend.new("config/locales/mf/*.yml"),
|
|
88
|
+
I18n::Backend::Simple.new
|
|
89
|
+
)
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
- Loads translations from separate, configurable file paths (glob patterns)
|
|
93
|
+
- All strings in those files are treated as Message Format patterns
|
|
94
|
+
- On `translate`: parses the pattern (or fetches from cache), formats with arguments
|
|
95
|
+
- Returns `nil` for missing keys so Chain falls through to the next backend
|
|
96
|
+
- Uses standard i18n YAML structure (`en.some.key`)
|
|
97
|
+
|
|
98
|
+
## LRU Cache
|
|
99
|
+
|
|
100
|
+
- Keyed by raw pattern string
|
|
101
|
+
- Default capacity: 1000 entries (configurable)
|
|
102
|
+
- Thread-safe via `Mutex`
|
|
103
|
+
- Stores parsed AST nodes
|
|
104
|
+
|
|
105
|
+
## Public API
|
|
106
|
+
|
|
107
|
+
```ruby
|
|
108
|
+
# Standalone usage
|
|
109
|
+
I18n::MessageFormat.format(
|
|
110
|
+
"{name} has {count, plural, one {# item} other {# items}}",
|
|
111
|
+
name: "Alice", count: 3
|
|
112
|
+
)
|
|
113
|
+
# => "Alice has 3 items"
|
|
114
|
+
|
|
115
|
+
# Backend integration
|
|
116
|
+
I18n.backend = I18n::Backend::Chain.new(
|
|
117
|
+
I18n::MessageFormat::Backend.new("config/locales/mf/*.yml"),
|
|
118
|
+
I18n::Backend::Simple.new
|
|
119
|
+
)
|
|
120
|
+
I18n.t("items.count", name: "Alice", count: 3)
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## Error Handling
|
|
124
|
+
|
|
125
|
+
- `I18n::MessageFormat::ParseError` — malformed patterns (includes line/column)
|
|
126
|
+
- `I18n::MessageFormat::MissingArgumentError` — required argument not provided
|
|
127
|
+
- Both inherit from `I18n::MessageFormat::Error`
|
|
128
|
+
|
|
129
|
+
## Dependencies
|
|
130
|
+
|
|
131
|
+
- **Runtime**: `i18n` gem only
|
|
132
|
+
- **Development**: `minitest`, `rake`
|
|
133
|
+
- **Ruby**: >= 3.2.0
|
|
134
|
+
|
|
135
|
+
## Testing
|
|
136
|
+
|
|
137
|
+
- Minitest
|
|
138
|
+
- Parser tests covering all node types, nesting, edge cases, and error reporting
|
|
139
|
+
- Formatter tests for each format type with multiple locales
|
|
140
|
+
- Backend integration tests with Chain
|
|
141
|
+
- Cache behavior tests
|