https://github.com/giantappman/multilanguageforxaml
Support WPF multi-language switching with JSON files | 用JSON文件支持WPF多语言切换
https://github.com/giantappman/multilanguageforxaml
i18n multi-language multi-language-support multilingual wpf xaml
Last synced: about 1 month ago
JSON representation
Support WPF multi-language switching with JSON files | 用JSON文件支持WPF多语言切换
- Host: GitHub
- URL: https://github.com/giantappman/multilanguageforxaml
- Owner: GiantappMan
- License: mit
- Created: 2018-07-31T07:09:23.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2024-01-12T02:00:41.000Z (over 1 year ago)
- Last Synced: 2024-04-27T00:42:48.483Z (about 1 year ago)
- Topics: i18n, multi-language, multi-language-support, multilingual, wpf, xaml
- Language: C#
- Homepage:
- Size: 1.45 MB
- Stars: 29
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# MultiLanguageForXAML
针对 WPF 的多语言支持库
## [Nuget](https://www.nuget.org/packages/MultiLanguageForXAML/)
## 效果预览
- **WPF**

## 用法
- **定义语言文件**
```
//Languages/zh.json 编译时拷贝到目录
{
"txt": "一",
"format":"你好 {0} !",
"world":"世界"
}//Languages/en.json 编译时拷贝到目录
{
"txt": "one",
"format":"hello {0} !",
"world":"world"
}```
- **初始化**
```csharp
//WPF
//怀疑用Environment.CurrentDirectory开机启动时目录会出错,待验证
string appDir = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
string path = Path.Combine(appDir, "Res\\Languages");
LanService.Init(new JsonFileDB(path), true,"zh");
//嵌入模式
//LanService.Init(new EmbeddedJsonDB("Samples.WPF.EmbeddedConfig.Languages"), true, "en");
```- **XAML**
```XAML
```
- **切换语言**
```csharp
//WPF
LanService.UpdateCulture("en");
```- **自定义控件映射(可选)**
```csharp
Xaml.CustomMaps.Add(typeof(CustomTitleBar), CustomTitleBar.TitleProperty);```
## 广而告之
[应用推荐]([https://giantapp.cn/categories/products](https://www.mscoder.cn/projects)https://www.mscoder.cn/projects)