Skip to content

Commit

Permalink
Add doc.
Browse files Browse the repository at this point in the history
  • Loading branch information
walterlv committed Jun 14, 2024
1 parent b679432 commit a233d6c
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ static void Main()

- Source Generators
- [x] Generate C# codes
- [ ] Generate properties for implementation types (so that reflections on types can get localized properties which is very important for WPF Bindings)
- [ ] Generate localized types for each language item which contains more than one arguments (This fixes different argument orders among different languages.)
- File formats
- [x] TOML
- [x] YAML `🤡 Might be deprecated in the future.`
Expand All @@ -32,6 +34,7 @@ static void Main()
- [ ] Detect (and generate) missing localization keys
- [ ] Detect (and remove) unused localization keys
- [ ] Detect arguments mismatch among localized texts (e.g. `Hello, {name:string}` in en but `こんにちは、{errorCode:int}` in ja)
- [ ] Detect invalid IETF language tags and report errors

## Installation

Expand Down Expand Up @@ -83,3 +86,43 @@ namespace SampleApp;
[LocalizedConfiguration(Default = "en", Current = "zh-hans")]
public partial class LocalizedText;
```

### 3. Use the generated code

```csharp
// Program.cs
static void Main()
{
Console.WriteLine(LocalizedText.Current.App.Title); // "Hello, World!"
Console.WriteLine(LocalizedText.Current.App.Description); // "This is a sample application."
Console.WriteLine(LocalizedText.Current.Cli.Usage); // "Usage: dotnetCampus.SourceLocalizations [options]"
Console.WriteLine(LocalizedText.Current.PressAnyKeyToExit); // "Press any key to exit..."
}
```

```xml
<!-- Avalonia MainWindow.axaml -->
<TextBlock Text="{Binding App.Title, Source={x:Static l:LocalizedText.Current}}" />
<TextBlock Text="{Binding App.Description, Source={x:Static l:LocalizedText.Current}}" />
```

```xml
<!-- Uno Platform MainPage.xaml -->
<TextBlock Text="{x:Bind l:Lang.Current.App.Title}" />
<TextBlock Text="{x:Bind l:Lang.Current.App.Description}" />
```

```csharp
// Uno Platform MainPage.xaml.cs
using dotnetCampus.Localizations;

namespace dotnetCampus.SampleUnoApp;

public sealed partial class MainPage : Page
{
public MainPage() => InitializeComponent();

// IMPORTANT: The Lang property must be public.
public ILocalizedValues Lang => global::dotnetCampus.SampleUnoApp.Localizations.LocalizedText.Current;
}
```

0 comments on commit a233d6c

Please sign in to comment.