Skip to content

Commit cc4405e

Browse files
committed
Rephrase documentation
1 parent 6981a8f commit cc4405e

File tree

2 files changed

+72
-44
lines changed

2 files changed

+72
-44
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Flow Launcher Localization Toolkit
22

3-
Localization toolkit for Flow Launcher and its plugins
3+
Localization toolkit for Flow Launcher and its plugins.
44

55
Useful links:
66

77
* [Flow Launcher localization toolkit guide](https://www.flowlauncher.com/docs/#/localization-toolkit)
8-
* [.Net plugin development guide](https://www.flowlauncher.com/docs/#/develop-dotnet-plugins)
8+
* [.NET plugin development guide](https://www.flowlauncher.com/docs/#/develop-dotnet-plugins)

localization-toolkit.md

Lines changed: 70 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,118 @@
1-
Localization toolkit is for Flow C# plugin developers to improve their localization experience.
1+
The Localization Toolkit helps Flow Launcher C# plugin developers make the localization process easier.
22

3-
## Initialization
3+
## Getting Started
44

5-
For C# Plugins, we need to install and reference [Flow.Launcher.Localization](www.nuget.org/packages/Flow.Launcher.Localization) by Nuget.
5+
For C# plugins, install and reference [Flow.Launcher.Localization](www.nuget.org/packages/Flow.Launcher.Localization) via NuGet.
66

7-
## Build properties
7+
## Build Properties
8+
9+
These are properties you can configure in your `.csproj` file to customize the localization process. You can set them in the `<PropertyGroup>` section. For example, to set the `FLLUseDependencyInjection` property to `true`, add the following lines:
10+
11+
```xml
12+
<PropertyGroup>
13+
<FLLUseDependencyInjection>true</FLLUseDependencyInjection>
14+
</PropertyGroup>
15+
```
816

917
### `FLLUseDependencyInjection`
1018

11-
Whether to use dependency injection to get `IPublicAPI` instance. Default by false.
12-
If set to `false`, the `Main` class that implements **[IPlugin](/API-Reference/Flow.Launcher.Plugin/IPlugin.md)** or **[IAsyncPlugin](/API-Reference/Flow.Launcher.Plugin/IAsyncPlugin.md)** must have a [PluginInitContext](/API-Reference/Flow.Launcher.Plugin/PluginInitContext.md) property which must be at least `internal static`.
19+
This flag specifies whether to use dependency injection to obtain an IPublicAPI instance. The default is `false`.
20+
- If set to `false`, the Main class (which must implement **[IPlugin](/API-Reference/Flow.Launcher.Plugin/IPlugin.md)** or **[IAsyncPlugin](/API-Reference/Flow.Launcher.Plugin/IAsyncPlugin.md)**)
21+
must have a [PluginInitContext](/API-Reference/Flow.Launcher.Plugin/PluginInitContext.md) property that is at least `internal static`.
22+
- If set to `true`, you can access the `IPublicAPI` instance via `PublicApi.Instance` using dependency injection, and the Main class does not need to include a [PluginInitContext](/API-Reference/Flow.Launcher.Plugin/PluginInitContext.md) property.
23+
(Note: This approach is not recommended for plugin projects at the moment since it limits compatibility to Flow Launcher 1.20.0 or later.)
1324

14-
If set to `true`, we can access `IPublicAPI` instance from `PublicApi.Instance` in the project by dependency injection.
15-
And the `Main` class does not need to have a [PluginInitContext](/API-Reference/Flow.Launcher.Plugin/PluginInitContext.md) property.
16-
(Not recommended for plugin projects because this will make plugins only compatible with Flow 1.20.0 or higher)
1725
## Usage
1826

19-
### Main class
27+
### Main Class
2028

21-
`Main` class must implement [IPluginI18n](/API-Reference/Flow.Launcher.Plugin/IPluginI18n.md).
29+
The Main class must implement [IPluginI18n](/API-Reference/Flow.Launcher.Plugin/IPluginI18n.md).
2230

23-
If `FLLUseDependencyInjection` is set to `false`, `Main` class must have a [PluginInitContext](/API-Reference/Flow.Launcher.Plugin/PluginInitContext.md) property like:
31+
If `FLLUseDependencyInjection` is `false`, include a [PluginInitContext](/API-Reference/Flow.Launcher.Plugin/PluginInitContext.md) property, for example:
2432

25-
```
26-
public class Main : IPlugin, IPluginI18n // Must implement IPluginI18n
33+
```csharp
34+
// Must implement IPluginI18n
35+
public class Main : IPlugin, IPluginI18n
2736
{
28-
internal static PluginInitContext Context { get; private set; } = null!; // At least internal static property
29-
private static IPublicAPI API => Context.API;
30-
31-
...
37+
// Must be at least internal static
38+
internal static PluginInitContext Context { get; private set; } = null!;
3239
}
3340
```
3441

35-
### Localized strings
42+
### Localized Strings
43+
44+
You can simplify your code by replacing calls like:
45+
```csharp
46+
Context.API.GetTranslation("flowlauncher_plugin_localization_demo_plugin_name")
47+
```
48+
with:
49+
```csharp
50+
Localize.flowlauncher_plugin_localization_demo_plugin_name()
51+
```
3652

37-
With this toolkit, we can replace `Context.API.GetTranslation("flowlauncher_plugin_localization_demo_plugin_name")` with `Localize.flowlauncher_plugin_localization_demo_plugin_name()`.
53+
If your localization string uses variables, it becomes even simpler! From this:
54+
```csharp
55+
string.Format(Context.API.GetTranslation("flowlauncher_plugin_localization_demo_value_with_keys"), firstName, lastName);
56+
```
57+
To this:
58+
```csharp
59+
Localize.flowlauncher_plugin_localization_demo_value_with_keys(firstName, lastName);
60+
```
3861

39-
And we can also replace `string.Format(Context.API.GetTranslation("flowlauncher_plugin_localization_demo_plugin_used"), string.Empty, null, string.Empty)` with `Localize.flowlauncher_plugin_localization_demo_plugin_used(string.Empty, null, string.Empty)`.
62+
### Localized Enums
4063

41-
### Localized enums
64+
For enum types (e.g., DemoEnum) that need localization in UI controls such as combo boxes, use the `EnumLocalize` attribute to enable localization. For each enum field:
65+
- Use `EnumLocalizeKey` to provide a custom localization key.
66+
- Use `EnumLocalizeValue` to provide a constant localization string.
4267

43-
If you have enum types like `DemoEnum` that needs localization in displaying them on a combo box control. You can add `EnumLocalize` attribute to enable localization support.
44-
For all fields in this `EnumType`, if you want to specific one localization key for this field, you can use `EnumLocalizeKey` attribute; or if you want to specific one constant value for this field, you can use `EnumLocalizeValue` attribute.
68+
Example:
4569

46-
```
70+
```csharp
4771
[EnumLocalize] // Enable localization support
4872
public enum DemoEnum
4973
{
50-
[EnumLocalizeKey("localize_key_1")] // Specific localization key
74+
// Specific localization key
75+
[EnumLocalizeKey("localize_key_1")]
5176
Value1,
5277

53-
[EnumLocalizeValue("localize_value_2")] // Specific localization value
78+
// Specific localization value
79+
[EnumLocalizeValue("This is my enum value localization")]
5480
Value2,
5581

56-
[EnumLocalizeKey("localize_key_3")] // If key and value both exist, will prefer localization key
57-
[EnumLocalizeValue("localize_value_3")]
82+
// Key takes precedence if both are present
83+
[EnumLocalizeKey("localize_key_3")]
84+
[EnumLocalizeValue("Localization Value")]
5885
Value3,
5986

60-
[EnumLocalizeKey(nameof(Localize.flowlauncher_plugin_localization_demo_plugin_description))] // Use Localize class
87+
// Using the Localize class. This way, you can't misspell localization keys, and if you rename
88+
// them in your .xaml file, you won't forget to rename them here as well because the build will fail.
89+
[EnumLocalizeKey(nameof(Localize.flowlauncher_plugin_localization_demo_plugin_description))]
6190
Value4,
6291
}
6392
```
6493

65-
Then you can get `DemoEnumData` class.
94+
Then, use the generated DemoEnumData class within your view model to bind to a combo box:
6695

67-
In view model class which needs to display it on a combo box control, you can add two fields for binding `ItemSource` and `SelectedValue` like:
96+
```csharp
97+
// ComboBox ItemSource
98+
public List<DemoEnumData> AllDemoEnums { get; } = DemoEnumData.GetValues();
6899

100+
// ComboBox SelectedValue
101+
public DemoEnum SelectedDemoEnum { get; set; }
69102
```
70-
public List<DemoEnumData> AllDemoEnums { get; } = DemoEnumData.GetValues(); // ItemSource of ComboBox
71103

72-
public DemoEnum SelectedDemoEnum { get; set; } // SelectedValue of ComboBox
73-
```
104+
In your XAML, bind as follows:
74105

75-
```
106+
```xml
76107
<ComboBox
77108
DisplayMemberPath="Display"
78109
ItemsSource="{Binding AllDemoEnums}"
79110
SelectedValue="{Binding SelectedDemoEnum}"
80111
SelectedValuePath="Value" />
81112
```
82113

83-
If you want to update localization strings when culture info changes, you can call this function to update.
114+
To update localization strings when the language changes, you can call:
84115

85-
```
86-
private void UpdateEnumDropdownLocalizations()
87-
{
88-
DemoEnumData.UpdateLabels(AllDemoEnums);
89-
}
116+
```csharp
117+
DemoEnumData.UpdateLabels(AllDemoEnums);
90118
```

0 commit comments

Comments
 (0)