我正在构建一个需要以多种语言和语言环境提供的应用程序.
我的问题不仅仅是技术问题,而是关于架构,以及人们实际在生产中用来解决这个问题的模式.我找不到任何"食谱",所以我转向我最喜欢的Q/A网站:)
这是我的要求(它们真的是"标准"):
以下是我可以想到的可能解决方案:
每个组件都孤立地处理翻译
这意味着每个组件具有例如一组en.json,fr.json等文件以及与翻译的字符串一起的文件.还有一个辅助函数可以帮助读取取决于所选语言的值.
每个组件通过道具接收翻译
所以他们不知道当前的语言,他们只是将字符串列表作为与当前语言匹配的道具
你稍微绕过了道具,并可能使用上下文来传递当前语言
如果您有任何其他想法,请说!
你怎么做呢?
在对集合进行排序时,我遇到了一个非常奇怪的.NET框架行为.这种行为在.NET 3.5和4.0之间是不同的(但我想我知道为什么),但更重要的是(这是我真正关心的),在同一框架上的不同机器上的行为是不同的.
我正在开发一种依赖某些第三方软件的软件(在这种情况下是spring.net,但这并不重要),并且在某些时候,它正在整理一个集所有项目"相等"的集合(比较器总是返回0).这不在我的控制之下,如果排序该列表的行为始终一致,我会很好.不是.
在.NET 3.5中创建一个简单的项目,然后运行下面的代码.当在3.5中编译时,行为似乎是一致的,并且集合将被"反转"(它出现为Three,Two,One).现在,请将项目目标更改为.NET 4(而不是4.5),然后再次运行:在我的计算机上,它不再反转集合(一,二,三),但在其他同事机器上,它确实(三二一)!!!我们有完全相同的设置......
你可以告诉我,在你的机器上,4.0以下,它是什么?反转还是不反转?
我正在尝试评估我的设置是否正确.
class Program
{
static void Main()
{
var collection = new ArrayList
{
"One",
"Two",
"Three",
};
// It should in any case write One, Two, Three
Console.Out.WriteLine("Before sort: ");
foreach (string item in collection)
{
Console.Out.WriteLine("\t"+item);
}
collection.Sort(new OrderComparator());
// In .NET 3.5, it will write Three, Two, One
// In .NET 4, it will …Run Code Online (Sandbox Code Playgroud) 我无法解决看似基本的MEF问题:我有2个"插件"项目(我们称之为P1和P2),以及两个插件共用的第三个项目(我们称之为C) .P1和P2都参考C.
尝试导入位于P1中的组件时,它会失败,因为此组件依赖于C中的组件.
这是跟踪:
System.ComponentModel.Composition警告:1:ComposablePartDefinition 'MyCompany.Client.Pms.Plugin.InclusionList.ViewModel.InclusionListViewModel' 已被拒绝.构图保持不变.由于以下错误,更改被拒绝:组合产生多个组合错误,有4个根本原因.根本原因如下.查看CompositionException.Errors属性以获取更多详细信息.
1)没有出口找到匹配约束 "((exportDefinition.ContractName = "MyCompany.Client.Plugins.Common.Controls.Selectors.PortfolioSelectors.ViewModel.ICalypsoBookSelectorViewModel")&&(exportDefinition.Metadata.ContainsKey( "ExportTypeIdentity")&& "MyCompany.Client.Plugins.Common.Controls.Selectors.PortfolioSelectors.ViewModel.ICalypsoBookSelectorViewModel" .Equals(exportDefinition.Metadata.get_Item( "ExportTypeIdentity"))))".
导致:无法设置进口"MyCompany.Client.Pms.Plugin.InclusionList.ViewModel.InclusionListViewModel.CalypsoBookSelectorViewModel(ContractName ='MyCompany.Client.Plugins.Common.Controls.Selectors.PortfolioSelectors.ViewModel.ICalypsoBookSelectorViewModel’)"关于部分"MyCompany的.Client.Pms.Plugin.InclusionList.ViewModel.InclusionListViewModel".元件:MyCompany.Client.Pms.Plugin.InclusionList.ViewModel.InclusionListViewModel.CalypsoBookSelectorViewModel(ContractName = "MyCompany.Client.Plugins.Common.Controls.Selectors.PortfolioSelectors.ViewModel.ICalypsoBookSelectorViewModel") - > MyCompany.Client.Pms.Plugin .InclusionList.ViewModel.InclusionListViewModel - > DirectoryCatalog(PATH = "C:\工作\ mmtrader \仪表板\代码\ SRC \仪表板\ MM \操盘\ BIN \调试\插件\位置")
[...](其他3个问题在不同的视图模型上完全相同)
我查看了MEF目录,结果发现MEF知道那些视图模型,所以我不知道缺少什么.
根据Dennis的要求,以下是我的导入/导出:
出口:
Export(typeof(ICalypsoBookSelectorViewModel))]
public class CalypsoBookSelectorViewModel : ScreenWithCleanupLifecycle, ICalypsoBookSelectorViewModel
{...}
Run Code Online (Sandbox Code Playgroud)
进口:
[Import(typeof(ICalypsoBookSelectorViewModel))]
public ICalypsoBookSelectorViewModel CalypsoBookSelectorViewModel { get; set; }
Run Code Online (Sandbox Code Playgroud)
目录:

在此先感谢您的帮助!
我正在努力解决过去几个月一直在唠叨我的困境.
我和我的同事对技术问题完全不同意,我希望我们心爱的社区对此事的看法.
是否最好使用枚举(具有潜在的属性,如"描述"),或使用实体(具有名称和描述属性)?
在我们的域模型中,我们有很多迷你实体,只包含Id,名称和描述.95%的时间,描述等于名称.
为了便于解释,我将采用众多示例中的一个:在我们的Security实体中,我们有一个AssetClass属性.AssetClass具有静态值列表("Equity","Bond"等),并且不会从界面或其他任何内容更改.
问题在于,当你想要获得资产类别为"Bond"的所有证券时,NHibernate将不得不加入AssetClass表......并且考虑到AssetClass不是唯一这样的属性,你可以想象所有这些联接的性能影响.
我们在代码中有一些硬编码的AssetClass实例及其各自的值和ID(即ID为1的Equity,Id为2的Bond等),它们匹配数据库中的内容:
public partial class AssetClass
{
static public AssetClass Equity = new AssetClass(1, "Equity", "Equity");
static public AssetClass Bond = new AssetClass(2, "Bond", "Bond");
static public AssetClass Future = new AssetClass(3, "Future", "Future");
static public AssetClass SomethingElse = new AssetClass(4, "Something else", "This is something else");
}
Run Code Online (Sandbox Code Playgroud)
我们还制作了一个特殊的NHibernate类型(如果你感兴趣的话,下面的代码)允许我们通过加载那个硬编码的实例来避免NHibernate做一个连接,而不是去数据库来获取它:
using System;
using System.Data;
using System.Data.Common;
using NHibernate.Dialect;
using NHibernate.SqlTypes;
using NHibernate.Type;
namespace MyCompany.Utilities.DomainObjects
{
public abstract class PrimitiveTypeBase<T> : PrimitiveType where T …Run Code Online (Sandbox Code Playgroud) 我需要格式化数字(使用WPF转换器),我能做到的唯一方法是通过string.Format.
我有两个格式参数:比例和精度. 我可以单独实现我需要的东西,但它不能同时兼顾:
示例(有效):
string.Format("{0:#,##0,,}", 1234567890.123m) == "1,235"
string.Format("{0:#,#.000}", 1234567890.123m) == "1,234,567,890.123"
Run Code Online (Sandbox Code Playgroud)
我需要的:
string.Format("????", 1234567890.123m) == "1,234.568"
Run Code Online (Sandbox Code Playgroud)
(这意味着1,234.568百万)你可以看到我找不到既可以缩放也可以显示小数的格式模式.
任何的想法?
我已经开始在新项目中使用Jest,现在我正在使用Jest 的Snapshot功能.
简而言之,它的作用是将您的组件呈现在一个字符串中,将其存储在磁盘上(作为快照,您可以在您的仓库中签入),并且当您稍后运行测试时,它将比较快照没有不要改变.
我的问题是导入图像:
使用Jest处理它的常用方法是指定一个用于导入它们的处理程序,模拟它们并返回一个随机字符串.这样,您的测试将不必实际加载图像,它将被模拟(否则您将获得异常,因为Node不知道如何处理import img from './image.png,只有Webpack通过加载器执行).
在Jest配置中,您可以执行以下操作:
"jest": {
"moduleNameMapper": {
"^.+\\.(png|jpg|jpeg|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/app/__mocks__/fileMock.js",
"^.+\\.(css|less|scss)$": "identity-obj-proxy"
},
[...]
}
Run Code Online (Sandbox Code Playgroud)
正如你所看到的,图像(png,jpeg等)都是使用fileMock "解决"的,就是这样:
module.exports = 'test-file-stub';
Run Code Online (Sandbox Code Playgroud)
我的问题是模拟有点太过分了:它总是返回相同的字符串,这意味着我的快照用于呈现标志的组件:
exports[`components - Flag should match the snapshot 1`] = `
<img
alt="Flag"
className="image"
src="test-file-stub" />
`;
Run Code Online (Sandbox Code Playgroud)
(输入是这样的<Flag country="fr" />)
我想要的是我的快照如此呈现:
exports[`components - Flag should match the snapshot 1`] = `
<img
alt="Flag"
className="image"
src="/some/path/fr.png" />
`;
Run Code Online (Sandbox Code Playgroud)
我不相信我是唯一一个面临这个问题的人,但另一方面我无法找到解决这个问题的任何资源.
谢谢!
c# ×4
.net ×2
reactjs ×2
.net-4.0 ×1
.net-4.5 ×1
architecture ×1
composition ×1
entities ×1
enumeration ×1
format ×1
javascript ×1
jestjs ×1
mef ×1
nhibernate ×1
redux ×1
string ×1
translation ×1
unit-testing ×1