1
0
mirror of https://github.com/bitwarden/mobile.git synced 2024-06-28 10:54:59 +02:00

fixes to i18n service

This commit is contained in:
Kyle Spearrin 2019-04-11 15:43:13 -04:00
parent 6ee109dc80
commit 567d527a71
4 changed files with 25 additions and 8 deletions

View File

@ -4,6 +4,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Bit.App.Pages.GeneratorPage"
xmlns:pages="clr-namespace:Bit.App.Pages"
xmlns:i18n="clr-namespace:Bit.App.Utilities"
x:DataType="pages:GeneratorPageViewModel"
Title="{Binding PageTitle}">
<ContentPage.BindingContext>
@ -16,6 +17,10 @@
Text="Generator!"
HorizontalOptions="Center"
VerticalOptions="CenterAndExpand" />
<Label
Text="{i18n:Translate AttachmentLargeWarning, P1='10 MB'}"
HorizontalOptions="Center"
VerticalOptions="CenterAndExpand" />
<Label
Text="&#xf2b9;"
HorizontalOptions="Center"

View File

@ -10,7 +10,7 @@ namespace Bit.App.Services
{
public class MobileI18nService : II18nService
{
private const string ResourceId = "UsingResxLocalization.Resx.AppResources";
private const string ResourceId = "Bit.App.Resources.AppResources";
private static readonly Lazy<ResourceManager> _resourceManager = new Lazy<ResourceManager>(() =>
new ResourceManager(ResourceId, IntrospectionExtensions.GetTypeInfo(typeof(MobileI18nService)).Assembly));
@ -41,12 +41,12 @@ namespace Bit.App.Services
Thread.CurrentThread.CurrentUICulture = Culture;
}
public string T(string id, params string[] p)
public string T(string id, string p1, string p2, string p3)
{
return Translate(id, p);
return Translate(id, p1, p2, p3);
}
public string Translate(string id, params string[] p)
public string Translate(string id, string p1, string p2, string p3)
{
if(string.IsNullOrWhiteSpace(id))
{
@ -61,7 +61,19 @@ namespace Bit.App.Services
result = $"{{{id}}}";
}
}
return string.Format(result, p);
if(p1 == null && p2 == null && p3 == null)
{
return result;
}
else if(p2 == null && p3 == null)
{
return string.Format(result, p1);
}
else if(p3 == null)
{
return string.Format(result, p1, p2);
}
return string.Format(result, p1, p2, p3);
}
}
}

View File

@ -6,7 +6,7 @@ using Xamarin.Forms.Xaml;
namespace Bit.App.Utilities
{
[ContentProperty("Text")]
[ContentProperty("Id")]
public class TranslateExtension : IMarkupExtension
{
private II18nService _i18nService;

View File

@ -5,7 +5,7 @@ namespace Bit.Core.Abstractions
public interface II18nService
{
CultureInfo Culture { get; set; }
string T(string id, params string[] p);
string Translate(string id, params string[] p);
string T(string id, string p1, string p2, string p3);
string Translate(string id, string p1, string p2, string p3);
}
}