/// <summary> /// Add AbpFx Resource /// </summary> /// <param name="services"></param> /// <param name="virtualPath"></param> /// <returns></returns> /// <exception cref="ArgumentNullException"></exception> public static II18NServiceCollection AddAbpResourceFrom(this II18NServiceCollection services, string virtualPath) { if (services == null) { throw new ArgumentNullException(nameof(services)); } if (string.IsNullOrWhiteSpace(virtualPath)) { throw new ArgumentNullException(nameof(virtualPath)); } var path = PathHelper.Combine(services.ExposeOptions, virtualPath, true); try { foreach (var filePath in PathHelper.GetSeveralPathList(path)) { using (var bridgeAdapter = new AbpJsonFileAdapter(filePath)) { if (bridgeAdapter.Process()) { var speaker = bridgeAdapter.Speak(); services.ExposeOptions.AddResource(speaker.PackageKey, TranslateResourceFactory.Create(speaker)); } } } } catch (Exception exception) { InternalLogger.WriteLine($"Thrown exception when add json resource from {path}, message: {0}", exception.Message); } return(services); }
private static II18NServiceCollection AddXmlAnonymousResourceFromOnce(II18NServiceCollection services, string path, bool referenceToBasePath) { try { using (var adapter = new AnonymousXmlFileAdapter(PathHelper.Combine(services.ExposeOptions, path, referenceToBasePath))) { if (adapter.Process()) { var speaker = adapter.Speak(); services.ExposeOptions.AddAnonymousResource(TranslateResourceFactory.Create(speaker)); } } } catch (Exception exception) { InternalLogger.WriteLine($"Thrown exception when add json resource from {path}, message: {0}", exception.Message); } return(services); }
/// <summary> /// Add xml format resource /// </summary> /// <param name="services"></param> /// <param name="originContext"></param> /// <returns></returns> /// <exception cref="ArgumentNullException"></exception> public static II18NServiceCollection AddXmlResource(this II18NServiceCollection services, string originContext) { if (services is null) { throw new ArgumentNullException(nameof(services)); } if (string.IsNullOrWhiteSpace(originContext)) { throw new ArgumentNullException(nameof(originContext)); } using (var adapter = new XmlContentAdapter(originContext)) { if (adapter.Process()) { var speaker = adapter.Speak(); services.ExposeOptions.AddResource(speaker.PackageKey, TranslateResourceFactory.Create(speaker)); } } return(services); }