Skip to content

Commit 5969b77

Browse files
committed
Update README
1 parent 37bef9a commit 5969b77

1 file changed

Lines changed: 24 additions & 14 deletions

File tree

README.md

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
- [1. Usage in XAML.](#1-usage-in-xaml)
1212
- [1.1. Bind a localized string.](#11-bind-a-localized-string)
1313
- [1.2. Errorhandling.](#12-errorhandling)
14-
- [1.3. EffectiveCulture.](#13-effectiveculture)
15-
- [1.4. Binding to CurrentCulture and EffectiveCulture in XAML.](#14-binding-to-currentculture-and-effectiveculture-in-xaml)
14+
- [1.3. CurrentCulture.](#13-currentculture)
15+
- [1.4. Binding to CurrentCulture and CurrentCulture in XAML.](#14-binding-to-currentculture-and-currentculture-in-xaml)
1616
- [2. Usage in code.](#2-usage-in-code)
1717
- [2.1. Translator.](#21-translator)
1818
- [2.1.1. Culture.](#211-culture)
1919
- [2.1.2. Culture.](#212-culture)
20-
- [2.1.3. EffectiveCulture.](#213-effectiveculture)
20+
- [2.1.3. CurrentCulture.](#213-currentculture)
2121
- [2.1.4. Cultures.](#214-cultures)
2222
- [2.1.5. ErrorHandling.](#215-errorhandling)
2323
- [2.1.6. Translate.](#216-translate)
@@ -28,6 +28,8 @@
2828
- [2.1.6.5. Translate with parameter:](#2165-translate-with-parameter)
2929
- [2.2. Translator<T>.](#22-translatort)
3030
- [2.3. Translation.](#23-translation)
31+
- [2.3.1 GetOrCreate.](#231-getorcreate)
32+
- [2.4. StaticTranslation.](#24-statictranslation)
3133
- [3. ErrorHandling.](#3-errorhandling)
3234
- [3.1. Global setting](#31-global-setting)
3335
- [3.2. ErrorFormats](#32-errorformats)
@@ -47,7 +49,7 @@
4749

4850
The library has a `StaticExtension` markupextension that is used when translating.
4951
The reason for naming it `StaticExtension` and not `TranslateExtension` is that Resharper provides intellisense when named `StaticExtension`
50-
Binding the text like below updates the text when `Translator.EffectiveCulture`changes enabling runtime selection of language.
52+
Binding the text like below updates the text when `Translator.CurrentCulture`changes enabling runtime selection of language.
5153

5254
The markupextension has ErrorHandling = ErrorHandling.ReturnErrorInfoPreserveNeutral as default, it encodes errors in the result, see [ErrorFormats](#3-errorhandling))
5355
## 1.1. Bind a localized string.
@@ -63,7 +65,7 @@ The markupextension has ErrorHandling = ErrorHandling.ReturnErrorInfoPreserveNeu
6365
...
6466
```
6567

66-
The above will show SomeResource in the `Translator.EffectiveCulture` and update when culture changes.
68+
The above will show SomeResource in the `Translator.CurrentCulture` and update when culture changes.
6769

6870
## 1.2. Errorhandling.
6971
By setting the attached property `ErrorHandling.Mode` we override how translation errors are handled by the `StaticExtension` for the child elements.
@@ -78,21 +80,21 @@ When null the `StaticExtension` uses ReturnErrorInfoPreserveNeutral
7880
...
7981
```
8082

81-
## 1.3. EffectiveCulture.
82-
A markupextension for accessing `Translator.EffectiveCulture` from xaml. Retruns a binding that updates when EffectiveCulture changes.
83+
## 1.3. CurrentCulture.
84+
A markupextension for accessing `Translator.CurrentCulture` from xaml. Retruns a binding that updates when CurrentCulture changes.
8385

8486
```xaml
85-
<Grid numeric:NumericBox.Culture="{l:EffectiveCulture}"
87+
<Grid numeric:NumericBox.Culture="{l:CurrentCulture}"
8688
... >
8789
...
8890
<StackPanel Orientation="Horizontal">
8991
<TextBlock Text="Effective culture: " />
90-
<TextBlock Text="{l:EffectiveCulture}" />
92+
<TextBlock Text="{l:CurrentCulture}" />
9193
</StackPanel>
9294
...
9395
```
9496

95-
## 1.4. Binding to CurrentCulture and EffectiveCulture in XAML.
97+
## 1.4. Binding to CurrentCulture and CurrentCulture in XAML.
9698
The static properties support binding. Use this XAML for a twoway binding:
9799
```xaml
98100
<TextBox Text="{Binding Path=(localization:Translator.CurrentCulture)}" />
@@ -109,13 +111,13 @@ Changing culture updates all translations. Setting culture to a culture for whic
109111
Get or set the current culture. The default is `null`
110112
Changing culture updates all translations. Setting culture to a culture for which there is no translation throws. Check ContainsCulture() first.
111113

112-
### 2.1.3. EffectiveCulture.
114+
### 2.1.3. CurrentCulture.
113115
Get the culture used in translations. By the following mechanism:
114116
1) CurrentCulture if not null.
115117
2) Any Culture in <see cref="Cultures"/> matching <see cref="CultureInfo.CurrentCulture"/> by name.
116118
3) Any Culture in <see cref="Cultures"/> matching <see cref="CultureInfo.CurrentCulture"/> by name.
117119
4) CultureInfo.InvariantCulture
118-
When this value changes EffectiveCultureChanged is raised and all translatins updates and notifies.
120+
When this value changes CurrentCultureChanged is raised and all translatins updates and notifies.
119121

120122
### 2.1.4. Cultures.
121123
Get a list with the available cultures. Cultures are found by looking in current directory and scanning for satellite assemblies.
@@ -176,8 +178,12 @@ string inSwedish = Translator.Translate(Properties.Resources.ResourceManager,
176178
Same as translator but used like `Translator<Properties.Resources>.Translate(...)`
177179

178180
## 2.3. Translation.
179-
An object with a Translated property that is a string with the value in `Translator.EffectiveCulture`
180-
Implements ÌNotifyPropertyChanged` and notifies when `Translator.EffectiveCulture` changes.
181+
An object with a Translated property that is a string with the value in `Translator.CurrentCulture`
182+
Implements ÌNotifyPropertyChanged` and notifies when for the property `Translated` if a change in `Translator.CurrentCulture` updates the translation.
183+
184+
## 2.3.1 GetOrCreate.
185+
Returns an `ITranslation` from cache or creates and caches a new instance.
186+
If ErrorHandling is Throw it throws if the key is missing. If other than throw a `StaticTranslation` is returned.
181187

182188
```c#
183189
Translation translation = Translation.GetOrCreate(Properties.Resources.ResourceManager, nameof(Properties.Resources.SomeResource))
@@ -210,6 +216,10 @@ namespace YourNamespace.Properties
210216
}
211217
```
212218

219+
## 2.4. StaticTranslation.
220+
An implementation of `ITranslation` that never updates the `Translated`property and returns the value of `Translated` when calling `Translate()`on it with any paramaters.
221+
This is returned from `Translation.GetOrCreate(...)` if the key is missing.
222+
213223
# 3. ErrorHandling.
214224
When calling the translate methods an ErrorHandling argument can be provided.
215225
If `ErrorHandling.ReturnErrorInfo` is passed in the method does not throw but returns information about the error in the string.

0 commit comments

Comments
 (0)