Skip to content

Instantly share code, notes, and snippets.

@spoo-bar
Last active May 9, 2019 11:51
Show Gist options
  • Save spoo-bar/75597c0be1f86d4be9f0264974b92a34 to your computer and use it in GitHub Desktop.
Save spoo-bar/75597c0be1f86d4be9f0264974b92a34 to your computer and use it in GitHub Desktop.
A custom translated resource text provider
internal class ResourceProvider : IResourceProvider
{
public IResourceReader ResourceReader => null;
public object GetObject(string resourceKey, CultureInfo culture)
{
if (culture.LCID == 1025) //1025 - Arabic
return "مرحبا";
else if (culture.LCID == 1036) //1036 - French
return "Bonjour";
else if (culture.LCID == 1081) //1081 - Hindi
return "नमस्ते";
return "Hello";
}
}
[DesignTimeResourceProviderFactory(typeof(ResourceProviderFactory))]
public class ResourceProviderFactory : System.Web.Compilation.ResourceProviderFactory
{
private ResourceProvider resourceProvider = new ResourceProvider();
public override IResourceProvider CreateGlobalResourceProvider(string classKey)
{
return resourceProvider;
}
public override IResourceProvider CreateLocalResourceProvider(string virtualPath)
{
return resourceProvider;
}
}
<configuration>
<location path="." allowOverride="true" inheritInChildApplications="false">
<system.web>
<globalization fileEncoding="utf-8" requestEncoding="utf-8" responseEncoding="utf-8" resourceProviderFactoryType="<%NAMESPACE%>.ResourceProviderFactory, <%NAMESPACE%>"/>
</system.web>
</location>
</configuration>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment