Commit 29e53d4f authored by Laurent Wouters's avatar Laurent Wouters
Browse files

Fixed issue #10129385 Automatic language selection

parent 3a5b4f9fa45d
......@@ -127,11 +127,11 @@ export interface RenderingContext {
*/
export interface ViewRenderer {
/**
* Selects the language to use for a target resource
* Selects the languages to use for a target resource
* @param context The current rendering context
* @param target The target resource for this view
*/
getLanguageFor(context: RenderingContext, target: string): Language;
getLanguagesFor(context: RenderingContext, target: string): Language[];
/**
* Renders a resource belonging to an RDF store
......
......@@ -244,12 +244,19 @@ class ViewRendererImpl implements ViewRenderer {
* @param context The current rendering context
* @param target The target resource for this view
*/
getLanguageFor(context: RenderingContext, target: string): Language {
getLanguagesFor(context: RenderingContext, target: string): Language[] {
let options = context.options[target];
if (options == undefined || options == null) return context.browserLanguage;
if (options.language == undefined || options.language == null)
return context.browserLanguage;
return options.language;
let result = [];
if (
options != undefined &&
options != null &&
options.language != undefined &&
options.language != null
)
result.push(options.language);
if (context.browserLanguage != null && context.browserLanguage != undefined)
result.push(context.browserLanguage);
return result;
}
/**
......
......@@ -153,15 +153,20 @@ interface FoaFPerson {
function getLiteralValue(
entity: RdfEntity,
property: string,
language: application.Language
languages: application.Language[]
): string {
let literals = entity.getValuesForS(property);
if (literals.length == 0) return null;
for (var i = 0; i != literals.length; i++) {
if (literals[i].termType != $rdf.Literal.termType) continue;
let lit = literals[i] as $rdf.Literal;
if (lit.lang == language.iso639_1 || lit.lang == language.iso639_2)
return literals[i].value;
for (var l = 0; l != languages.length; l++) {
for (var i = 0; i != literals.length; i++) {
if (literals[i].termType != $rdf.Literal.termType) continue;
let lit = literals[i] as $rdf.Literal;
if (
lit.lang == languages[l].iso639_1 ||
lit.lang == languages[l].iso639_2
)
return literals[i].value;
}
}
return literals[0].value;
}
......@@ -195,10 +200,10 @@ function loadPerson(
"http://xmlns.com/foaf/0.1/focus"
);
if (entityFocus != null) entityTarget = entityFocus;
let language = renderer.getLanguageFor(context, target);
let languages = renderer.getLanguagesFor(context, target);
function l(property: string): string {
return getLiteralValue(entityTarget, property, language);
return getLiteralValue(entityTarget, property, languages);
}
function r(property: string): string[] {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment