Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ this project adheres to [Semantic Versioning](https://semver.org/).
formatter that understands named arguments.
- `{l:LocalizeEnum}` re-resolves on every change of `ILocalizer.RefreshTriggeringRevision`, and so does
`LocalizeEnumConverter` with its new refresh-trigger child.
- The opt-in package `ResXLocalization.MessageFormat`: ICU MessageFormat (`plural`, `select`) through
`Localizer.Current.UseMessageFormat()`, which parses every resolved value as an ICU message, with or
without arguments, optionally with a configured `MessageFormatter` of the `MessageFormat` library. See
[ICU MessageFormat](docs/guides/message-format.md).

### Changed

Expand Down
2 changes: 2 additions & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
<PackageVersion Include="Avalonia.Fonts.Inter" Version="12.1.2" />
<PackageVersion Include="Avalonia.Themes.Fluent" Version="12.1.2" />
<PackageVersion Include="CommunityToolkit.Mvvm" Version="8.4.2" />
<!-- Shipped by ResXLocalization.MessageFormat, so this version is also that package's floor. -->
<PackageVersion Include="MessageFormat" Version="8.0.0" />

<!-- Source generator toolchain. -->
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="5.9.0" />
Expand Down
2 changes: 2 additions & 0 deletions ResXLocalization.NonWindows.slnf
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
"path": "ResXLocalization.slnx",
"projects": [
"src\\ResXLocalization.Core\\ResXLocalization.Core.csproj",
"src\\ResXLocalization.MessageFormat\\ResXLocalization.MessageFormat.csproj",
"src\\ResXLocalization.SourceGenerators\\ResXLocalization.SourceGenerators.csproj",
"src\\ResXLocalization.Avalonia\\ResXLocalization.Avalonia.csproj",
"samples\\ResXLocalization.Avalonia.Sample\\ResXLocalization.Avalonia.Sample.csproj",
"tests\\ResXLocalization.Avalonia.Sample.Tests\\ResXLocalization.Avalonia.Sample.Tests.csproj",
"tests\\ResXLocalization.Core.Tests\\ResXLocalization.Core.Tests.csproj",
"tests\\ResXLocalization.MessageFormat.Tests\\ResXLocalization.MessageFormat.Tests.csproj",
"tests\\ResXLocalization.SourceGenerators.Tests\\ResXLocalization.SourceGenerators.Tests.csproj"
]
}
Expand Down
2 changes: 2 additions & 0 deletions ResXLocalization.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<Folder Name="/01_src/">
<Project Path="src/ResXLocalization.Avalonia/ResXLocalization.Avalonia.csproj" />
<Project Path="src/ResXLocalization.Core/ResXLocalization.Core.csproj" />
<Project Path="src/ResXLocalization.MessageFormat/ResXLocalization.MessageFormat.csproj" />
<Project Path="src/ResXLocalization.SourceGenerators/ResXLocalization.SourceGenerators.csproj" />
<Project Path="src/ResXLocalization.WPF/ResXLocalization.WPF.csproj" />
</Folder>
Expand All @@ -12,6 +13,7 @@
<Folder Name="/03_tests/">
<Project Path="tests/ResXLocalization.Avalonia.Sample.Tests/ResXLocalization.Avalonia.Sample.Tests.csproj" />
<Project Path="tests/ResXLocalization.Core.Tests/ResXLocalization.Core.Tests.csproj" />
<Project Path="tests/ResXLocalization.MessageFormat.Tests/ResXLocalization.MessageFormat.Tests.csproj" />
<Project Path="tests/ResXLocalization.SourceGenerators.Tests/ResXLocalization.SourceGenerators.Tests.csproj" />
<Project Path="tests/ResXLocalization.WPF.Sample.Tests/ResXLocalization.WPF.Sample.Tests.csproj" />
</Folder>
Expand Down
3 changes: 3 additions & 0 deletions docs/guides/enums.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ explicitly:

Under the default formatter, a text that needs a plural - `1 file` and `3 files` - needs one enum
member per plural case: the default formatter is `string.Format` and does not choose between forms.
With the ICU MessageFormat formatter of the `ResXLocalization.MessageFormat` package, one member and a
`plural` pattern suffice, for example `{0, plural, one {# file} other {# files}}`; see
[ICU MessageFormat](message-format.md).

## Where a markup extension is not accepted: `LocalizeEnumConverter`

Expand Down
16 changes: 10 additions & 6 deletions docs/guides/format-arguments.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ the same, so a custom formatter reads `Position`.

**Names matter only to a formatter that understands them.** The default `string.Format` formatter
ignores names and uses positions, so `MessageArguments.FromObject(new { Count = 1.5, Where = "x" })` fills `{0}` and `{1}`
exactly like `MessageArguments.FromValues(1.5, "x")`. A formatter that knows names (ICU MessageFormat) finds a named
argument both under its position and under its name.
exactly like `MessageArguments.FromValues(1.5, "x")`. The ICU MessageFormat formatter of the
`ResXLocalization.MessageFormat` package finds a named argument both under its position and under its name;
see [ICU MessageFormat](message-format.md).

## In XAML

Expand Down Expand Up @@ -114,8 +115,9 @@ Localizer.Current.Get("FilePosition", MessageArguments.FromTuples((null, index),
Both become `MessageArgument`s - a position, an optional name and the resolved value - which is what a
custom formatter receives. The position of an `<l:Argument>` is its index among the children, whether it
has a name or not; the default formatter ignores names, so `File {0} of {1}` renders `File 3 of 10`
for `Index` 3 and `Count` 10. A formatter that understands names (ICU MessageFormat) finds a named
argument under its name too.
for `Index` 3 and `Count` 10. The ICU MessageFormat formatter of the `ResXLocalization.MessageFormat`
package finds a named argument under its name too, so `File {0} of {Total}` works there; see
[ICU MessageFormat](message-format.md).

## Worth knowing

Expand Down Expand Up @@ -181,5 +183,7 @@ argument under its name too.
```
- **Keep it simple.** For a very complex string, compose the text in the view model with
`Get(key, MessageArguments.FromValues(…))` rather than writing many `<l:Argument>` elements.
- **Composite formatting does not pluralize.** `1 people invited` is on the resource author; use
separate singular and plural resources where it matters.
- **Composite formatting does not pluralize.** Under the default formatter, `1 people invited` is on the
resource author; use separate singular and plural resources where it matters, or install the ICU
MessageFormat formatter of the `ResXLocalization.MessageFormat` package, whose `plural` chooses the form
by the count: see [ICU MessageFormat](message-format.md).
Loading
Loading