hi.
we have persistent objects that have a property "Label".
we would like to be able to "localize" these values, that is to say:
- the customer creates one of these objects
- then, he must be able to enter different values for different language
- later, in another app, the label property must be loaded according to a chosen language.
we consider 2 approaches:
- via custom classinfo, adding custom column "LabelFR", "LabelDE", etc…
- via xpcollection, that would link a key and its localizations
would you mind give us your feelings about these 2 ways, and / or suggest other solutions?
thanks
Localization of data property values based on external tables
Answers
Hi Michel,
I should say that XAF does not support this functionality internally, and in my opinion, this task is not specifically related to the XPO library. On a side note, I would prefer to have a separate table (a persistent class) for localized strings, and reference properties to this class for all localizable string properties in my project. For example:
C#[DefaultProperty("Value")]
public class LocalizableString : XPObject {
public LocalizableString(Session s) : base(s) { }
[Association("LocalizedStrings")]
public XPCollection<StringLocalization> Values {
get { return GetCollection<StringLocalization>("Values"); }
}
[PersistentAlias("iif(Values[Culture=CurrentUICulture()], Values[Culture=CurrentUICulture()].Max(Value), Values[IsNullOrEmpty(Culture)].Max(Value))")]
public string Value {
get {
return Convert.ToString(EvaluateAlias("Value"));
}
}
}
public class StringLocalization : XPObject {
public StringLocalization(Session s) : base(s) { }
public string Value;
[Indexed("Item", Unique = true)]
public string Culture;
[Association("LocalizedStrings")]
public LocalizableString Item;
}
[NavigationItem]
public class Class1 : XPObject {
public Class1(Session s) : base(s) { }
public LocalizableString PropertyA;
public LocalizableString PropertyB;
public LocalizableString PropertyC;
}
// Register this function by calling the CriteriaOperator.RegisterCustomFunction method
public class CurrentUICultureFinction : ICustomFunctionOperatorFormattable {
public string Format(Type providerType, params string[] operands) {
return string.Concat("'", System.Globalization.CultureInfo.CurrentUICulture.Name, "'");
}
public object Evaluate(params object[] operands) {
return System.Globalization.CultureInfo.CurrentUICulture.Name;
}
public string Name { get { return "CurrentUICulture"; } }
public Type ResultType(params Type[] operands) { return typeof(string); }
}
@Michael: my primary business requirement is to using the server mode on the all list views, as I know XPView/DataView does not support server mode? Can I ask you about implementing this support in the nearest version?
@Stanislaw: Implementing a new server mode source component based on XPView is not a simple task and we don't have immediate plans to do this. Anyway, thank you for your suggestion. Note that a similar scenario was also discussed in the S36566 ticket. You can add it to your favorites to be notified when anything changes.
A ticket about the solution with PersistentAlias in Server Mode: How to return property name from ICustomFunctionOperatorFormattable.Format method?