November Happy Hour will be moved to Thursday December 5th.
November Happy Hour will be moved to Thursday December 5th.
I think <enums> should appear directly beneath <language>.
In this case I think the <property> between them is incorrect, as its the enum itself you're defining a translation for not a property.
Actually that may be just difference in our implementation.
Our usage uses:
public class EnumSelectionFactory<TEnum> : ISelectionFactory
{
public IEnumerable<ISelectItem> GetSelections(ExtendedMetadata metadata)
{
var values = Enum.GetValues(typeof(TEnum));
var items = new List<ISelectItem>();
foreach (TEnum value in values)
{
items.Add(new SelectItem { Text = value.GetLocalisedString(), Value = value });
}
return items.OrderBy(i => i.Text);
}
}
With the extension method:
public static string GetLocalisedString<TEnum>(this TEnum value)
{
var name = Enum.GetName(typeof(TEnum), value);
string path = $"/enums/{typeof(TEnum).Name.ToLowerInvariant()}/{name?.ToLowerInvariant() ?? "null"}";
return LocalizationService.Current
.TryGetString(path, out var localisedName)
? localisedName
: name;
}
Might be a case of checking which bits you've borrowed from each article.
I'm suing Get.EPiExtenensions, and according to their implementation:
the key is build like `property/enum/<enum_type_name>/<enum_member_name>`. But the problem possibly might be elswhere. I dumped all localization entries, calling `
LocalizationService.Current.GetAllStrings();` and it turns our that I can't find anything that related the entries that I've created in thr XML, no `property` no `enum` no `blockcolumncount` and no entries for the enum members.
We're actually mostly using enums with SelectOne and Select Many, and not actually using the Geta extensions so perhaps I've miunderstood. But that's how we do it anyhow,
[Display(
GroupName = SystemTabNames.Content,
Order = 250)]
[SelectMany(SelectionFactoryType = typeof(EnumSelectionFactory<MemberStatus>))]
public virtual string MemberStatusTypes { get; set; }
[Display(GroupName = SystemTabNames.Content, Order = 350)]
[SelectOne(SelectionFactoryType = typeof(EnumSelectionFactory<Global.Theme>))]
public virtual Global.Theme Theme { get; set; }
Web.config entry looks fine - I presume that's within <episerver.framework> and that the /Resources/LanguageFiles/ is within the web app project and not a class library.
I believe that alone should be enough to see it if you inspect the localization service directly. I have found that I have sometimes needed to recycle the app pool when adding for them to show up.
Other things worth looking out for may be typos, errors in the logs reading files perhaps, perhaps checking XML files don't contain any odd leading characters. I tend to create mine directly in Visual Studio on Windows but if I'm receiving files sometimes I use Visual Studio code to look for any hidden characters which might throw out the processing.
Just to confirm if there is an issue parsing the XML file it doesn't cause the app to crash but does show in the logs, and obviously does cause it to be missing from the locaization service - I deliberately added a leading space to my file to test it, I get this:
2020-07-13 13:12:48,661 [172] ERROR EPiServer.Framework.Localization.XmlResources.FileXmlLocalizationProvider: Unhandled exception while handling FileSystemWatcher event Renamed on file C:\<path to web app root>\Resources\LanguageFiles\Enums.xml.
System.Configuration.ConfigurationErrorsException: Unexpected XML declaration. The XML declaration must be the first node in the document, and no white space characters are allowed to appear before it. Line 1, position 4. (/Resources/LanguageFiles/Enums.xml line 1) ---> System.Xml.XmlException: Unexpected XML declaration. The XML declaration must be the first node in the document, and no white space characters are allowed to appear before it. Line 1, position 4.
You could also use this trick to check it is seeing and attempting to read the file itself by deliberately adding a leading space and seeing if that causes you to see the error message. I'm presuming it could be the case for other characters too.
I had some errors from FileXmlLocalizationProvider but when I intentionally messed up the configuration while testing. I can see that when I edit the XML file diretctly, it throws an error because it complains that the file is being used by another process, so it clearly sees the file and listens to changes. Yet the entries are not resolved.
Hmm, try updating the language XML file so that language looks like the following with the name attribute - just realised I have that on mine and you don't and I think that may be making a difference:
<language name="English" id="en">
I'm using `Enum` from Geta EPi.Extensions attribute on a block propert, which implement ideas following these blog posts:
http://joelabrahamsson.com/enum-properties-with-episerver/
https://world.episerver.com/Blogs/Linus-Ekstrom/Dates/2014/5/Enum-properties-for-EPiServer-75/
Everything is working fine, except the translations for enum properties are not being picked in the UI.
My enum looks like this:
My property like that:
My localization configuration in web config:
My language file:
I have the file in the correct localization:
This is how the UI looks - lables from XML file are not showing up.
According to this post, it should work to add /property/enum/<type>/<member> into /languages/language, but it's not working for me and at that point of time I don't have any idea what's going on. Please advise.