Translations
In next steps is a description of Translation using and overriding
Step 1: Creating .csv
Create .csv file In that file you define keys which Translation service will use, and languages for that keys. For example
Resource,en-US,ro
core_payments,Payments2,Payments ro
Note
If you want to use a comma within your translation text, you should wrap the whole sentence in "", like this: core_payments,"Payments, 2, with comma","Payments, ro, with comma"
Step 2: Registering .csv
In Application.cs in methode
protected override void RegisterTypes(ITypeCatalog typeCatalog){}
need to add your own transaltion .csv file
typeCatalog.Add(new TranslationResourceInfo(typeof(DigitalEdgeMobileApplication))
{
Path = "AssecoSEE.DEM.Customizations.Data.customTranslations.csv",
Priority = 100
});
Step 3: Using Transaltion from xaml
Header of your xaml page need to mapp namespace for translation comonent
xmlns:ext="clr-namespace:AssecoSEE.DEM.Components.XamlExtensions;assembly=AssecoSEE.DEM.Components"
And after that copy key from .csv file and use it in xaml
<Label AbsoluteLayout.LayoutBounds="0.5,0.2,1,0.25"
AbsoluteLayout.LayoutFlags="All"
FontSize="Medium"
Margin="10"
HorizontalTextAlignment="Center"
Text="{ext:Translate core_pin_enter}"
TextColor="{StaticResource WhiteColor}"
VerticalTextAlignment="Center" />
If you want upper case wrapped your key with ($!your_key) for example
<Label Text="{ext:Translate ($!foundation_change_password)}"
FontSize="Medium"
FontAttributes="Bold"
Margin="10,0,10,10"
TextColor="{StaticResource BlackColor}"
HorizontalOptions="CenterAndExpand"
VerticalOptions="CenterAndExpand"/>
Using transaltion from Binding value with BindingValueTranslateConverter
<Label Text="{TemplateBinding Path=BindingContext.CurrentProduct.Value.FinancingKind, Converter={StaticResource BindingValueTranslateConverter}}"
FontSize="12"
TextColor="Black"
FontAttributes="Bold" />
Step 4: Using Translatino from code
In any ViewModel you can call Transaltion service App.Translate["your_key"];
SuccessfulPaymentMessage = App.Translation["payment_successful_topup_description"];
FailedPaymentMessage = App.Translation["payment_failed_topup_description"];
Server Integration
We made the class StartupManager that receives a list of tasks (IEnumerable
Each of them gets registered through DI afterwards, and we have made several of them so far which are executed according to the given priority from 1 to 100 Translation correction on the server The application checks if there is something new before startup And based on that, it updates local cache, although here we have to separate what is for web and what is for mobile so as not to receive bunch of translation. Afterwards, this received translation gets cached locally and if the cache gets erased the dates are reset to initial; then everything is received again and bigger download follows, so this part has to get tested additionally for sure. Configurations
We did the same thing for configuration as well public interface ISyncService : IApplicationService
{
int Priority { get; }
Task SyncAsync();
string Method { get; }
}
Translations
public virtual async Task SyncAsync()
{
var ctx = new Rest.Common.Context.ClientInvocationContext()
{
APIUrl = config.FactoryConfig_API_Endpoint,
PreferredClientCulture = config.FactoryConfig_API_ClientCulture,
ApplicationAccessToken = tokenManager.GetToken()
};
cache.TryGetValue(lastUsedKey, out string lastUsed);
using (RequestService rs = new RequestService(
config, cache, logger, ctx, connection))
{
var syncTimestamp = String.IsNullOrWhiteSpace(lastUsed) ? appInfo.ApplicationStartSyncDate : lastUsed;
List<DateTime> maxDateTimeLIst = new List<DateTime>();
foreach (var item in config.FactoryConfig_SupportedLanguages)
{
var lang = item.Value;
var list = await rs.GetAsync<
AssecoSEE.Rest.DialogAPI.DataContracts.Models.LocalizationStrings.LocalizedValueList>(
$"v1/dialog/localization/{lang}?sync-timestamp={syncTimestamp}");
if (list.HasData() && list.Data.Items != null && list.Data.Items.Where(t => !String.IsNullOrWhiteSpace(t.SyncTimestamp)).Any())
{
try
{
var tranlsateDictionary = list.Data.Items?.Select(t => new KeyValuePair<string, string>(t.LocalizationKeyId, t.Value)).ToDictionary(
x => x.Key, x => x.Value);
translation.Update(lang, tranlsateDictionary, syncTimestamp);
try
{
var maxDateTime = list.Data.Items.Where(t => !String.IsNullOrWhiteSpace(t.SyncTimestamp)).Select(t => t.SyncTimestamp.ToDateTime()).Max();
if (maxDateTime != null)
{
maxDateTimeLIst.Add(maxDateTime);
}
}
catch (Exception ex)
{
logger.Log(ADebugLevel.Diagnostic, "maxDateTime", ex);
}
}
catch (Exception ex)
{
logger.Log(ADebugLevel.Diagnostic, "Update Translation Dictionary", ex);
}
}
}
if (maxDateTimeLIst != null && maxDateTimeLIst.Any())
{
cache.AddOrUpdate(lastUsedKey, maxDateTimeLIst.Max().AddSeconds(30).ToLoggerDateTimeString(), TimeSpan.MaxValue);
}
}
}
Note