Commits

Jason Perkins committed 40abf3c

Add locale() to specify culture codes for Visual Studio C/C++ resources

  • Participants
  • Parent commits 563eef5

Comments (0)

Files changed (6)

src/_premake_init.lua

 	}
 
 	api.register {
+		name = "locale",
+		scope = "config",
+		kind = "string",
+		tokens = false,
+	}
+
+	api.register {
 		name = "location",
 		scope = "project",
 		kind = "path",

src/actions/vstudio/_vstudio.lua

 
 
 --
+-- Mapping from ISO locales to MS culture identifiers.
+-- http://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo%28v=vs.85%29.ASPX
+--
+
+	vstudio._cultures = {
+		["af"] = 0x0036,
+		["af-ZA"] = 0x0436,
+		["sq"] = 0x001C,
+		["sq-AL"] = 0x041C,
+		["ar"] = 0x0001,
+		["ar-DZ"] = 0x1401,
+		["ar-BH"] = 0x3C01,
+		["ar-EG"] = 0x0C01,
+		["ar-IQ"] = 0x0801,
+		["ar-JO"] = 0x2C01,
+		["ar-KW"] = 0x3401,
+		["ar-LB"] = 0x3001,
+		["ar-LY"] = 0x1001,
+		["ar-MA"] = 0x1801,
+		["ar-OM"] = 0x2001,
+		["ar-QA"] = 0x4001,
+		["ar-SA"] = 0x0401,
+		["ar-SY"] = 0x2801,
+		["ar-TN"] = 0x1C01,
+		["ar-AE"] = 0x3801,
+		["ar-YE"] = 0x2401,
+		["hy"] = 0x002B,
+		["hy-AM"] = 0x042B,
+		["az"] = 0x002C,
+		["az-Cyrl-AZ"] = 0x082C,
+		["az-Latn-AZ"] = 0x042C,
+		["eu"] = 0x002D,
+		["eu-ES"] = 0x042D,
+		["be"] = 0x0023,
+		["be-BY"] = 0x0423,
+		["bg"] = 0x0002,
+		["bg-BG"] = 0x0402,
+		["ca"] = 0x0003,
+		["ca-ES"] = 0x0403,
+		["zh-HK"] = 0x0C04,
+		["zh-MO"] = 0x1404,
+		["zh-CN"] = 0x0804,
+		["zh-Hans"] = 0x0004,
+		["zh-SG"] = 0x1004,
+		["zh-TW"] = 0x0404,
+		["zh-Hant"] = 0x7C04,
+		["hr"] = 0x001A,
+		["hr-HR"] = 0x041A,
+		["cs"] = 0x0005,
+		["cs-CZ"] = 0x0405,
+		["da"] = 0x0006,
+		["da-DK"] = 0x0406,
+		["dv"] = 0x0065,
+		["dv-MV"] = 0x0465,
+		["nl"] = 0x0013,
+		["nl-BE"] = 0x0813,
+		["nl-NL"] = 0x0413,
+		["en"] = 0x0009,
+		["en-AU"] = 0x0C09,
+		["en-BZ"] = 0x2809,
+		["en-CA"] = 0x1009,
+		["en-029"] = 0x2409,
+		["en-IE"] = 0x1809,
+		["en-JM"] = 0x2009,
+		["en-NZ"] = 0x1409,
+		["en-PH"] = 0x3409,
+		["en-ZA"] = 0x1C09,
+		["en-TT"] = 0x2C09,
+		["en-GB"] = 0x0809,
+		["en-US"] = 0x0409,
+		["en-ZW"] = 0x3009,
+		["et"] = 0x0025,
+		["et-EE"] = 0x0425,
+		["fo"] = 0x0038,
+		["fo-FO"] = 0x0438,
+		["fa"] = 0x0029,
+		["fa-IR"] = 0x0429,
+		["fi"] = 0x000B,
+		["fi-FI"] = 0x040B,
+		["fr"] = 0x000C,
+		["fr-BE"] = 0x080C,
+		["fr-CA"] = 0x0C0C,
+		["fr-FR"] = 0x040C,
+		["fr-LU"] = 0x140C,
+		["fr-MC"] = 0x180C,
+		["fr-CH"] = 0x100C,
+		["gl"] = 0x0056,
+		["gl-ES"] = 0x0456,
+		["ka"] = 0x0037,
+		["ka-GE"] = 0x0437,
+		["de"] = 0x0007,
+		["de-AT"] = 0x0C07,
+		["de-DE"] = 0x0407,
+		["de-LI"] = 0x1407,
+		["de-LU"] = 0x1007,
+		["de-CH"] = 0x0807,
+		["el"] = 0x0008,
+		["el-GR"] = 0x0408,
+		["gu"] = 0x0047,
+		["gu-IN"] = 0x0447,
+		["he"] = 0x000D,
+		["he-IL"] = 0x040D,
+		["hi"] = 0x0039,
+		["hi-IN"] = 0x0439,
+		["hu"] = 0x000E,
+		["hu-HU"] = 0x040E,
+		["is"] = 0x000F,
+		["is-IS"] = 0x040F,
+		["id"] = 0x0021,
+		["id-ID"] = 0x0421,
+		["it"] = 0x0010,
+		["it-IT"] = 0x0410,
+		["it-CH"] = 0x0810,
+		["ja"] = 0x0011,
+		["ja-JP"] = 0x0411,
+		["kn"] = 0x004B,
+		["kn-IN"] = 0x044B,
+		["kk"] = 0x003F,
+		["kk-KZ"] = 0x043F,
+		["kok"] = 0x0057,
+		["kok-IN"] = 0x0457,
+		["ko"] = 0x0012,
+		["ko-KR"] = 0x0412,
+		["ky"] = 0x0040,
+		["ky-KG"] = 0x0440,
+		["lv"] = 0x0026,
+		["lv-LV"] = 0x0426,
+		["lt"] = 0x0027,
+		["lt-LT"] = 0x0427,
+		["mk"] = 0x002F,
+		["mk-MK"] = 0x042F,
+		["ms"] = 0x003E,
+		["ms-BN"] = 0x083E,
+		["ms-MY"] = 0x043E,
+		["mr"] = 0x004E,
+		["mr-IN"] = 0x044E,
+		["mn"] = 0x0050,
+		["mn-MN"] = 0x0450,
+		["no"] = 0x0014,
+		["nb-NO"] = 0x0414,
+		["nn-NO"] = 0x0814,
+		["pl"] = 0x0015,
+		["pl-PL"] = 0x0415,
+		["pt"] = 0x0016,
+		["pt-BR"] = 0x0416,
+		["pt-PT"] = 0x0816,
+		["pa"] = 0x0046,
+		["pa-IN"] = 0x0446,
+		["ro"] = 0x0018,
+		["ro-RO"] = 0x0418,
+		["ru"] = 0x0019,
+		["ru-RU"] = 0x0419,
+		["sa"] = 0x004F,
+		["sa-IN"] = 0x044F,
+		["sr-Cyrl-CS"] = 0x0C1A,
+		["sr-Latn-CS"] = 0x081A,
+		["sk"] = 0x001B,
+		["sk-SK"] = 0x041B,
+		["sl"] = 0x0024,
+		["sl-SI"] = 0x0424,
+		["es"] = 0x000A,
+		["es-AR"] = 0x2C0A,
+		["es-BO"] = 0x400A,
+		["es-CL"] = 0x340A,
+		["es-CO"] = 0x240A,
+		["es-CR"] = 0x140A,
+		["es-DO"] = 0x1C0A,
+		["es-EC"] = 0x300A,
+		["es-SV"] = 0x440A,
+		["es-GT"] = 0x100A,
+		["es-HN"] = 0x480A,
+		["es-MX"] = 0x080A,
+		["es-NI"] = 0x4C0A,
+		["es-PA"] = 0x180A,
+		["es-PY"] = 0x3C0A,
+		["es-PE"] = 0x280A,
+		["es-PR"] = 0x500A,
+		["es-ES"] = 0x0C0A,
+		["es-ES_tradnl"]= 0x040A,
+		["es-UY"] = 0x380A,
+		["es-VE"] = 0x200A,
+		["sw"] = 0x0041,
+		["sw-KE"] = 0x0441,
+		["sv"] = 0x001D,
+		["sv-FI"] = 0x081D,
+		["sv-SE"] = 0x041D,
+		["syr"] = 0x005A,
+		["syr-SY"] = 0x045A,
+		["ta"] = 0x0049,
+		["ta-IN"] = 0x0449,
+		["tt"] = 0x0044,
+		["tt-RU"] = 0x0444,
+		["te"] = 0x004A,
+		["te-IN"] = 0x044A,
+		["th"] = 0x001E,
+		["th-TH"] = 0x041E,
+		["tr"] = 0x001F,
+		["tr-TR"] = 0x041F,
+		["uk"] = 0x0022,
+		["uk-UA"] = 0x0422,
+		["ur"] = 0x0020,
+		["ur-PK"] = 0x0420,
+		["uz"] = 0x0043,
+		["uz-Cyrl-UZ"] = 0x0843,
+		["uz-Latn-UZ"] = 0x0443,
+		["vi"] = 0x002A,
+		["vi-VN"] = 0x042A,
+	}
+
+
+--
 -- Translate the system and architecture settings from a configuration
 -- into a corresponding Visual Studio identifier. If no settings are
 -- found in the configuration, a default value is returned, based on
 	end
 
 
+---
+-- Given an ISO locale identifier, return an MS culture code.
+---
+
+	function vstudio.cultureForLocale(locale)
+		if locale then
+			local culture = vstudio._cultures[locale]
+			if not culture then
+				premake.warnOnce("Locale" .. locale, 'Unsupported locale "%s"', locale)
+			end
+			return culture
+		end
+	end
+
+
 --
 -- Return true if the configuration kind is one of "Makefile" or "None". The
 -- latter is generated like a Makefile project and excluded from the solution.

src/actions/vstudio/vs200x_vcproj.lua

 
 		m.resourcePreprocessorDefinitions(cfg)
 		m.resourceAdditionalIncludeDirectories(cfg)
+		m.culture(cfg)
 
 		p.pop('/>')
 	end
 	end
 
 
+
+	function m.culture(cfg)
+		local value = vstudio.cultureForLocale(cfg.locale)
+		if value then
+			p.w('Culture="%d"', value)
+		end
+	end
+
+
+
 	function m.customBuildTool(filecfg)
 		if fileconfig.hasCustomBuildRule(filecfg) then
 			p.x('CommandLine="%s"', table.concat(filecfg.buildcommands,'\r\n'))

src/actions/vstudio/vs2010_vcxproj.lua

 	vc2010.elements.resourceCompile = {
 		"resourcePreprocessorDefinitions",
 		"resourceAdditionalIncludeDirectories",
+		"culture",
 	}
 
 	function vc2010.resourceCompile(cfg)
 	end
 
 
+	function vc2010.culture(cfg)
+		local value = vstudio.cultureForLocale(cfg.locale)
+		if value then
+			_p(3,'<Culture>0x%04x</Culture>', value)
+		end
+	end
+
+
 	function vc2010.debugInformationFormat(cfg)
 		local value
 		if cfg.flags.Symbols then

tests/actions/vstudio/vc200x/test_resource_compiler.lua

 />
 		]]
 	end
+
+
+--
+-- Test locale conversion to culture codes.
+--
+
+	function suite.culture_en_NZ()
+		locale "en-NZ"
+		prepare()
+		test.capture [[
+<Tool
+	Name="VCResourceCompilerTool"
+	Culture="5129"
+/>
+		]]
+	end

tests/actions/vstudio/vc2010/test_resource_compile.lua

 			<PreprocessorDefinitions>VERSION_STRING=\"1.0.0 (testing)\";%(PreprocessorDefinitions)</PreprocessorDefinitions>
 		]]
 	end
+
+
+--
+-- Test locale conversion to culture codes.
+--
+
+	function suite.culture_en_US()
+		locale "en-US"
+		prepare()
+		test.capture [[
+		<ResourceCompile>
+			<Culture>0x0409</Culture>
+		]]
+	end