rename from Pixiview to Gallery
This commit is contained in:
68
Gallery/Resources/Languages/zh-CN.xml
Executable file
68
Gallery/Resources/Languages/zh-CN.xml
Executable file
@ -0,0 +1,68 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<root>
|
||||
<Title>Gallery</Title>
|
||||
<Guest>游客</Guest>
|
||||
<Ok>OK</Ok>
|
||||
<Cancel>取消</Cancel>
|
||||
<Yes>是</Yes>
|
||||
<No>否</No>
|
||||
<Login>登录</Login>
|
||||
<About>关于</About>
|
||||
<Version>版本</Version>
|
||||
<Illusts>插画</Illusts>
|
||||
<Proxy>代理</Proxy>
|
||||
<Detail>详细</Detail>
|
||||
<Enabled>启用</Enabled>
|
||||
<Host>主机</Host>
|
||||
<Port>端口</Port>
|
||||
<Privacy>隐私</Privacy>
|
||||
<Cookie>Cookie</Cookie>
|
||||
<Daily>今日</Daily>
|
||||
<Weekly>本周</Weekly>
|
||||
<Monthly>本月</Monthly>
|
||||
<Male>受男性欢迎</Male>
|
||||
<monthly>当月截至 {0}</monthly>
|
||||
<weekly>当周截至 {0}</weekly>
|
||||
<daily>{0} 当日</daily>
|
||||
<male>{0} 最受欢迎</male>
|
||||
<monthly_r18>当月截至 {0}</monthly_r18>
|
||||
<weekly_r18>当周截至 {0}</weekly_r18>
|
||||
<daily_r18>{0} 当日</daily_r18>
|
||||
<male_r18>{0} 最受欢迎</male_r18>
|
||||
<General>一般</General>
|
||||
<R18>R-18</R18>
|
||||
<SyncType>收藏同步类型</SyncType>
|
||||
<SyncNo>不同步</SyncNo>
|
||||
<SyncPrompt>提示同步</SyncPrompt>
|
||||
<SyncAuto>自动同步</SyncAuto>
|
||||
<DownloadIllustThreads>下载线程数</DownloadIllustThreads>
|
||||
<Follow>已关注</Follow>
|
||||
<Recommends>推荐</Recommends>
|
||||
<ByUser>按用户</ByUser>
|
||||
<Ranking>排行榜</Ranking>
|
||||
<Search>搜索</Search>
|
||||
<Favorites>收藏夹</Favorites>
|
||||
<Option>选项</Option>
|
||||
<Preview>预览</Preview>
|
||||
<Operation>操作</Operation>
|
||||
<SaveOriginal>保存原图</SaveOriginal>
|
||||
<Share>分享</Share>
|
||||
<UserDetail>浏览用户</UserDetail>
|
||||
<RelatedIllusts>相关推荐</RelatedIllusts>
|
||||
<SaveSuccess>成功保存图片到照片库。</SaveSuccess>
|
||||
<AlreadySavedQuestion>原图已保存,是否继续?</AlreadySavedQuestion>
|
||||
<InvalidUrl>无法识别该 URL。</InvalidUrl>
|
||||
<FavoritesOperation>请选择收藏夹操作</FavoritesOperation>
|
||||
<FavoritesReplace>替换</FavoritesReplace>
|
||||
<FavoritesCombine>合并</FavoritesCombine>
|
||||
<ExportVideo>导出视频</ExportVideo>
|
||||
<CantExportVideo>无法导出视频,请先下载完成。</CantExportVideo>
|
||||
<AlreadySavedVideo>视频已保存,是否继续?</AlreadySavedVideo>
|
||||
<ExportSuccess>视频已导出到照片库。</ExportSuccess>
|
||||
<FailedResponse>无法获取返回结果。</FailedResponse>
|
||||
<ConfirmSyncFavorite>要同步收藏吗?</ConfirmSyncFavorite>
|
||||
<ConfirmLogin>当前身份为游客,是否跳转到登录页面?</ConfirmLogin>
|
||||
<All>所有</All>
|
||||
<Animation>动画</Animation>
|
||||
<Online>在线</Online>
|
||||
</root>
|
43
Gallery/Resources/PlatformCulture.cs
Executable file
43
Gallery/Resources/PlatformCulture.cs
Executable file
@ -0,0 +1,43 @@
|
||||
namespace Gallery.Resources
|
||||
{
|
||||
public class PlatformCulture
|
||||
{
|
||||
public string PlatformString { get; private set; }
|
||||
public string LanguageCode { get; private set; }
|
||||
public string LocaleCode { get; private set; }
|
||||
|
||||
public string Language
|
||||
{
|
||||
get { return string.IsNullOrEmpty(LocaleCode) ? LanguageCode : LanguageCode + "-" + LocaleCode; }
|
||||
}
|
||||
|
||||
public PlatformCulture() : this(null) { }
|
||||
public PlatformCulture(string cultureString)
|
||||
{
|
||||
if (string.IsNullOrEmpty(cultureString))
|
||||
{
|
||||
//throw new ArgumentNullException(nameof(cultureString), "Expected culture identieifer");
|
||||
cultureString = "en";
|
||||
}
|
||||
|
||||
PlatformString = cultureString.Replace('_', '-');
|
||||
var index = PlatformString.IndexOf('-');
|
||||
if (index > 0)
|
||||
{
|
||||
var parts = PlatformString.Split('-');
|
||||
LanguageCode = parts[0];
|
||||
LocaleCode = parts[parts.Length - 1];
|
||||
}
|
||||
else
|
||||
{
|
||||
LanguageCode = PlatformString;
|
||||
LocaleCode = "";
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return PlatformString;
|
||||
}
|
||||
}
|
||||
}
|
134
Gallery/Resources/ResourceHelper.cs
Executable file
134
Gallery/Resources/ResourceHelper.cs
Executable file
@ -0,0 +1,134 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Xml;
|
||||
using Xamarin.Forms;
|
||||
using Xamarin.Forms.Xaml;
|
||||
|
||||
namespace Gallery.Resources
|
||||
{
|
||||
public class ResourceHelper
|
||||
{
|
||||
public static string Title => GetResource(nameof(Title));
|
||||
public static string Guest => GetResource(nameof(Guest));
|
||||
public static string Ok => GetResource(nameof(Ok));
|
||||
public static string Cancel => GetResource(nameof(Cancel));
|
||||
public static string Yes => GetResource(nameof(Yes));
|
||||
public static string No => GetResource(nameof(No));
|
||||
public static string R18 => GetResource(nameof(R18));
|
||||
public static string SyncNo => GetResource(nameof(SyncNo));
|
||||
public static string SyncPrompt => GetResource(nameof(SyncPrompt));
|
||||
public static string SyncAuto => GetResource(nameof(SyncAuto));
|
||||
public static string Operation => GetResource(nameof(Operation));
|
||||
public static string SaveOriginal => GetResource(nameof(SaveOriginal));
|
||||
public static string Share => GetResource(nameof(Share));
|
||||
public static string UserDetail => GetResource(nameof(UserDetail));
|
||||
public static string RelatedIllusts => GetResource(nameof(RelatedIllusts));
|
||||
public static string SaveSuccess => GetResource(nameof(SaveSuccess));
|
||||
public static string AlreadySavedQuestion => GetResource(nameof(AlreadySavedQuestion));
|
||||
public static string InvalidUrl => GetResource(nameof(InvalidUrl));
|
||||
public static string Favorites => GetResource(nameof(Favorites));
|
||||
public static string FavoritesOperation => GetResource(nameof(FavoritesOperation));
|
||||
public static string FavoritesReplace => GetResource(nameof(FavoritesReplace));
|
||||
public static string FavoritesCombine => GetResource(nameof(FavoritesCombine));
|
||||
public static string ExportVideo => GetResource(nameof(ExportVideo));
|
||||
public static string CantExportVideo => GetResource(nameof(CantExportVideo));
|
||||
public static string AlreadySavedVideo => GetResource(nameof(AlreadySavedVideo));
|
||||
public static string ExportSuccess => GetResource(nameof(ExportSuccess));
|
||||
public static string FailedResponse => GetResource(nameof(FailedResponse));
|
||||
public static string ConfirmSyncFavorite => GetResource(nameof(ConfirmSyncFavorite));
|
||||
public static string ConfirmLogin => GetResource(nameof(ConfirmLogin));
|
||||
|
||||
static readonly Dictionary<string, LanguageResource> dict = new Dictionary<string, LanguageResource>();
|
||||
|
||||
public static string GetResource(string name, params object[] args)
|
||||
{
|
||||
if (!dict.TryGetValue(App.CurrentCulture.PlatformString, out LanguageResource lang))
|
||||
{
|
||||
lang = new LanguageResource(App.CurrentCulture);
|
||||
dict.Add(App.CurrentCulture.PlatformString, lang);
|
||||
}
|
||||
|
||||
if (args == null || args.Length == 0)
|
||||
{
|
||||
return lang[name];
|
||||
}
|
||||
return string.Format(lang[name], args);
|
||||
}
|
||||
|
||||
private class LanguageResource
|
||||
{
|
||||
private readonly Dictionary<string, string> strings;
|
||||
|
||||
public string this[string key]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (strings != null && strings.TryGetValue(key, out string val))
|
||||
{
|
||||
return val;
|
||||
}
|
||||
return key;
|
||||
}
|
||||
}
|
||||
|
||||
public LanguageResource(PlatformCulture lang)
|
||||
{
|
||||
try
|
||||
{
|
||||
#if __IOS__
|
||||
var langId = $"Gallery.iOS.Resources.Languages.{lang.Language}.xml";
|
||||
var langCodeId = $"Gallery.iOS.Resources.Languages.{lang.LanguageCode}.xml";
|
||||
#elif __ANDROID__
|
||||
var langId = $"Gallery.Droid.Resources.Languages.{lang.Language}.xml";
|
||||
var langCodeId = $"Gallery.Droid.Resources.Languages.{lang.LanguageCode}.xml";
|
||||
#endif
|
||||
var assembly = IntrospectionExtensions.GetTypeInfo(typeof(LanguageResource)).Assembly;
|
||||
var names = assembly.GetManifestResourceNames();
|
||||
var name = names.FirstOrDefault(n
|
||||
=> string.Equals(n, langId, StringComparison.OrdinalIgnoreCase)
|
||||
|| string.Equals(n, langCodeId, StringComparison.OrdinalIgnoreCase));
|
||||
if (name == null)
|
||||
{
|
||||
#if __IOS__
|
||||
name = "Gallery.iOS.Resources.Languages.zh-CN.xml";
|
||||
#elif __ANDROID__
|
||||
name = "Gallery.Droid.Resources.Languages.zh-CN.xml";
|
||||
#endif
|
||||
}
|
||||
var xml = new XmlDocument();
|
||||
using (var stream = assembly.GetManifestResourceStream(name))
|
||||
{
|
||||
xml.Load(stream);
|
||||
}
|
||||
strings = new Dictionary<string, string>();
|
||||
foreach (XmlElement ele in xml.DocumentElement) // .Root.Elements()
|
||||
{
|
||||
strings[ele.Name] = ele.InnerText; // .LocalName Value
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// load failed
|
||||
App.DebugError("language.ctor", $"failed to load xml resource: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[ContentProperty(nameof(Text))]
|
||||
public class TextExtension : IMarkupExtension
|
||||
{
|
||||
public string Text { get; set; }
|
||||
|
||||
public object ProvideValue(IServiceProvider serviceProvider)
|
||||
{
|
||||
if (Text == null)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
return ResourceHelper.GetResource(Text);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user