locale: Take encoding into account when resolving strings
This commit is contained in:
		
							parent
							
								
									1d3cdbe6a1
								
							
						
					
					
						commit
						2c7e8ef76d
					
				@ -18,10 +18,17 @@ export type string = [](locale, str);
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// Selects the most appropriate localized version of a [[string]] given a
 | 
					// Selects the most appropriate localized version of a [[string]] given a
 | 
				
			||||||
// [[locale]]. The matching algorithm used is the one specified by the
 | 
					// [[locale]]. The matching algorithm used is the one specified by the
 | 
				
			||||||
// XDG Desktop Entry Specification, §5. If no suitable version is found, an
 | 
					// XDG Desktop Entry Specification, §5, with the addition of a preliminary step
 | 
				
			||||||
// exact match with the C locale will be attempted. If there are none, void will
 | 
					// where a match against the exact locale is attempted. If no suitable version
 | 
				
			||||||
// be returned. Memory is borrowed from the input.
 | 
					// is found, an exact match with the C locale will be attempted. If there are
 | 
				
			||||||
export fn string_resolve(strin: string, local: locale) (str | void) = {	
 | 
					// none, void will be returned. Memory is borrowed from the input.
 | 
				
			||||||
 | 
					export fn string_resolve(strin: string, local: locale) (str | void) = {
 | 
				
			||||||
 | 
						// lang_COUNTRY@MODIFIER.ENCODING
 | 
				
			||||||
 | 
						match (string_resolve_exact(strin, local)) {
 | 
				
			||||||
 | 
						case let result: str => return result;
 | 
				
			||||||
 | 
						case                 => void;
 | 
				
			||||||
 | 
						};
 | 
				
			||||||
 | 
						
 | 
				
			||||||
	// lang_COUNTRY@MODIFIER
 | 
						// lang_COUNTRY@MODIFIER
 | 
				
			||||||
	let lang_country_modifier = local;
 | 
						let lang_country_modifier = local;
 | 
				
			||||||
	lang_country_modifier.encoding = "";
 | 
						lang_country_modifier.encoding = "";
 | 
				
			||||||
@ -74,6 +81,12 @@ export type strings = [](locale, []str);
 | 
				
			|||||||
// [[locale]]. See the documentation for [[string_resolve]] for more
 | 
					// [[locale]]. See the documentation for [[string_resolve]] for more
 | 
				
			||||||
// information.
 | 
					// information.
 | 
				
			||||||
export fn strings_resolve(strins: strings, local: locale) ([]str | void) = {
 | 
					export fn strings_resolve(strins: strings, local: locale) ([]str | void) = {
 | 
				
			||||||
 | 
						// lang_COUNTRY@MODIFIER.ENCODING
 | 
				
			||||||
 | 
						match (strings_resolve_exact(strins, local)) {
 | 
				
			||||||
 | 
						case let result: []str => return result;
 | 
				
			||||||
 | 
						case                   => void;
 | 
				
			||||||
 | 
						};
 | 
				
			||||||
 | 
						
 | 
				
			||||||
	// lang_COUNTRY@MODIFIER
 | 
						// lang_COUNTRY@MODIFIER
 | 
				
			||||||
	let lang_country_modifier = local;
 | 
						let lang_country_modifier = local;
 | 
				
			||||||
	lang_country_modifier.encoding = "";
 | 
						lang_country_modifier.encoding = "";
 | 
				
			||||||
 | 
				
			|||||||
@ -7,6 +7,16 @@
 | 
				
			|||||||
		(c, "c"),
 | 
							(c, "c"),
 | 
				
			||||||
		(parse("xx_XX")!, "xx_XX"),
 | 
							(parse("xx_XX")!, "xx_XX"),
 | 
				
			||||||
	], parse("xx_XX.UTF-8")!) as str == "xx_XX");
 | 
						], parse("xx_XX.UTF-8")!) as str == "xx_XX");
 | 
				
			||||||
 | 
						assert(string_resolve([
 | 
				
			||||||
 | 
							(c, "c"),
 | 
				
			||||||
 | 
							(parse("xx_XX")!, "xx_XX"),
 | 
				
			||||||
 | 
							(parse("xx_XX.UTF-8")!, "xx_XX2"),
 | 
				
			||||||
 | 
						], parse("xx_XX")!) as str == "xx_XX");
 | 
				
			||||||
 | 
						assert(string_resolve([
 | 
				
			||||||
 | 
							(c, "c"),
 | 
				
			||||||
 | 
							(parse("xx_XX")!, "xx_XX"),
 | 
				
			||||||
 | 
							(parse("xx_XX.UTF-8")!, "xx_XX2"),
 | 
				
			||||||
 | 
						], parse("xx_XX.UTF-8")!) as str == "xx_XX2");
 | 
				
			||||||
	assert(string_resolve([
 | 
						assert(string_resolve([
 | 
				
			||||||
		(c, "c"),
 | 
							(c, "c"),
 | 
				
			||||||
		(parse("xx_XX")!, "xx_XX"),
 | 
							(parse("xx_XX")!, "xx_XX"),
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user