using Utils;

namespace System.Web.Mvc
{
/// <summary>
/// 本地化帮助类
/// </summary>
public static class LocalizationHelpers
{
/// <summary>
/// 在Html中直接使用,对页面元素输出字符串
/// webform中:<%= Html.Lang("String1") %>
/// mvc中:@Html.Lang("TaskType")
/// </summary>
/// <param name="htmlhelper"></param>
/// <param name="key"></param>
/// <returns></returns>
public static string Lang(this HtmlHelper htmlhelper, string key)
{
// 资源文件路径
string FilePath = htmlhelper.ViewContext.HttpContext.Server.MapPath("/") + "Resource\\";
return GetLangString(htmlhelper.ViewContext.HttpContext, key, FilePath);
} /// <summary>
/// 在Html中直接使用,对JS输出字符串
/// JS中:<%= Html.LangOutJsVar("String1")%> || @Html.Lang("String1")
/// JS中:alert(String1)
/// </summary>
/// <param name="htmlhelper"></param>
/// <param name="key"></param>
/// <returns></returns>
public static string LangOutJsVar(this HtmlHelper htmlhelper, string key)
{
// 资源文件路径
string FilePath = htmlhelper.ViewContext.HttpContext.Server.MapPath("/") + "Resource\\";
string langstr = GetLangString(htmlhelper.ViewContext.HttpContext, key, FilePath);
return string.Format("var {0} = '{1}'", key, langstr);
} /// <summary>
/// 在C#中使用,对后台输出字符串
/// ViewData["Message"] = LocalizationHelpers.InnerLang(this.ControllerContext.HttpContext, "String1");
/// </summary>
/// <param name="httpContext"></param>
/// <param name="key"></param>
/// <returns></returns>
public static string InnerLang(HttpContextBase httpContext, string key)
{
string FilePath = httpContext.Server.MapPath("/") + "Resource\\";
return GetLangString(httpContext, key, FilePath);
} /// <summary>
/// 输出字符串
/// </summary>
/// <param name="httpContext"></param>
/// <param name="key"></param>
/// <param name="FilePath"></param>
/// <returns></returns>
private static string GetLangString(HttpContextBase httpContext, string key, string FilePath)
{
int langtype = ;
if (SessionHelper.GetSession("Lang") != null)
{
langtype = (SessionHelper.GetSession("Lang").ToString().Equals("en")) ? : ;
} try
{
System.Resources.ResourceManager rs;
switch (langtype)
{
case : rs = new System.Resources.ResourceManager("Utils.Lang_zh", typeof(Lang_zh).Assembly); break;
case : rs = new System.Resources.ResourceManager("Utils.Lang_en", typeof(Lang_en).Assembly); break;
default: rs = new System.Resources.ResourceManager("Utils.Lang_zh", typeof(Lang_zh).Assembly); break;
} return rs.GetString(key);
}
catch (Exception ex)
{
}
return "";
}
}
}

C# LocalizationHelpers (搬运)的更多相关文章

  1. 关于codeblock中一些常用的快捷键(搬运)

    关于codeblock中一些常用的快捷键(搬运) codeblock作为一个常用的C/C++编译器,是我最常用的一款编译器,但也因为常用,所以有时为了更加快速的操作难免会用到一些快捷键,但是因为我本身 ...

  2. 搬运:Python for Windows——监控Windows某个目录下文件的变化

    https://win32com.goermezer.de/content/view/286/285/ 这个网站真是给力,不多说,代码直接搬运过来,还有我的测试结果,拿走不谢! import os i ...

  3. BizTalk开发系列(二) "Hello World" 程序搬运文件

    我们在<QuickLearn BizTalk系列之"Hello World">里讲到了如何快速的开发第一个BizTalk 应用程序.现在我们来讲一下如何把这个程序改成用 ...

  4. [置顶] 《算法导论》习题解答搬运&&学习笔记 索引目录

    开始学习<算法导论>了,虽然是本大部头,可能很难一下子看完,我还是会慢慢地研究的. 课后的习题和思考有些是很有挑战性的题目,我等蒻菜很难独立解决. 然后发现了Google上有挺全的algo ...

  5. (搬运)《算法导论》习题解答 Chapter 22.1-1(入度和出度)

    (搬运)<算法导论>习题解答 Chapter 22.1-1(入度和出度) 思路:遍历邻接列表即可; 伪代码: for u 属于 Vertex for v属于 Adj[u] outdegre ...

  6. 货物搬运(move)

    货物搬运(move) 题目描述 天地无情人有情,一方有难八方支援!汶川大地震发生后,灾区最紧缺的是救灾帐篷,全国各地支援的帐篷正紧急向灾区运送.假设围绕纹川县有环行排列的n个救灾帐篷的存储点,每个存储 ...

  7. stm32 DMA数据搬运 [操作寄存器+库函数](转)

    源:stm32 DMA数据搬运 [操作寄存器+库函数]        DMA(Direct Memory Access)常译为“存储器直接存取”.早在Intel的8086平台上就有了DMA应用了.   ...

  8. 用于NLP的CNN架构搬运:from keras0.x to keras2.x

    本文亮点: 将用于自然语言处理的CNN架构,从keras0.3.3搬运到了keras2.x,强行练习了Sequential+Model的混合使用,具体来说,是Model里嵌套了Sequential. ...

  9. 如何在CentOS 7上部署Google BBR【搬运、机翻】

    如何在CentOS 7上部署Google BBR 本文章搬运自 https://www.vultr.com/docs/how-to-deploy-google-bbr-on-centos-7 [注:文 ...

随机推荐

  1. char* 转换成 CString

    真是有意思: CString mess ;    mess = m_chLocalIP; 这样OK,但是写在一行就会报错 CString mess  = m_chLocalIP; //有问题

  2. Bug Tracker

    Bug Tracker 使用笔记(有图有真相)   目的:管理Bug,完善业务流程. 前提条件:BugTracker是基于IIS和SQL Server和Asp.Net的.相当于一个Web端的管理系统. ...

  3. 企业架构研究总结(30)——TOGAF架构内容框架之内容元模型(上)

    2. 内容元模型(Content Metamodel) 在TOGAF的眼中,企业架构是以一系列架构构建块为基础的,并将目录.矩阵和图形作为其具体展现方式.如果我们把这些表述方式看作为构建块的语法,那么 ...

  4. div光标定位问题总结

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  5. 用Jekyll在github上写博客

    用Jekyll在github上写博客——<搭建一个免费的,无限流量的Blog>的注脚 本来打算买域名,买空间,用wordpress写博客的.后来问了一个师兄,他说他是用github的空间, ...

  6. hdu1686

    题目意思:找到上串在下串中有多少个 Problem Description The French author Georges Perec (1936–1982) once wrote a book, ...

  7. 数据结构中的棧在C#中的实现

    数据结构中的棧在C#中的实现 一.大致学习 棧是一种面向表的数据结构,棧中的数据只能在标的某一短进行添加和删除操作,是一种典型的(LIFO)数据结构. 现实生活中的理解:自助餐厅的盘子堆,人们总是从顶 ...

  8. C# 加密总结 一些常见的加密方法

    C# 加密总结 一些常见的加密方法 一 散列数据 代码如下: ? private static string CalculateSHA512Hash(string input)         {   ...

  9. kivy create a package for Android

    Now that you've successfully coded an app. Now you want to deploy it to Android. So now we would nee ...

  10. C#中 如何执行带GO的sql 语句

    C#中是不允许执行带GO的sql 语句的, 如何做呢? 思路就是将带GO的sql语句转化为分段执行, 但在同一事务内执行. 扩展方法是个很不错的主意, 但是尽量不要影响原来的cmd的一些东东, 如 c ...