Skip to content

Localization issues #483

Open
Open
@FrantisekBodnar

Description

@FrantisekBodnar

Hi I would like to thank you for this library, it is great help in MVC application :)

But I found a several bugs MvcSiteMapProvider when I would like to use resource files for mvcSiteMapNode.

For Title & Description properties / attributes it works only with Explicit localization ($resources: ...).
When you try to use Implicit localization (use with resourceKey attribute), you will always get empty value or better say, it will return value specified in mvcSiteMapNode attribute in the XML sitemap file, but not from Resource file (in format ResourceKey.Attribute).

I checked the code, and the problem is that MvcSiteMapProvider.SiteMap class has invalid value in ResourceKey property, that returns SiteMapCacheKey (that is generated by ISiteMapCacheKeyGenerator.GenerateKey()) value that returns a string in format "sitemap://hostname/", but it should return Resource file Class Key (that is resource filename without resx extension). Without it, it will never return valid value from any Resource file.

public virtual string ResourceKey
{
	get
	{
		return this.siteMapSettings.SiteMapCacheKey;
	}
	set
	{
	}
}

For custom attributes in mvcSiteMapNode it doesn't work for any type of localization.
This time the problem is in MvcSiteMapProvider.Collections.Specialized.AttributeDictionary.Add() method, where is no reading from Resource file implemented at all (for Explicit & Implicit localization). It just parse string via MvcSiteMapProvider.Globalization.IExplicitResourceKeyParser.HandleResourceAttribute() method to determine if Explicit localization is used or not.

public void Add(string key, object value, bool throwIfReservedKey)
{
	if (this.reservedAttributeNameProvider.IsRegularAttribute(key))
	{
		if (value.GetType().Equals(typeof(string)))
			value = localizationService.ExtractExplicitResourceKey(key, value.ToString());

		if (!this.ContainsKey(key))
			base.Add(key, value);
		else
			base[key] = value;
	}
	else if (throwIfReservedKey)
	{
		throw new ReservedKeyException(string.Format(Resources.Messages.AttributeKeyReserved, this.siteMapNodeKey, key, value));
	}
}

Hopefully you would have time to fix it in next releases, so we can use the library with proper localization features. :)

Thanks for help
Franky

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions