Last active
May 9, 2019 11:51
-
-
Save spoo-bar/75597c0be1f86d4be9f0264974b92a34 to your computer and use it in GitHub Desktop.
A custom translated resource text provider
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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