¿Cómo puedo usar el idioma actual como variable en mi página maestra?
-
10-12-2019 - |
Pregunta
Soy diseñador web que trabaja con SharePoint 2013. Creé una plantilla personalizada para una empresa y ahora quiero ir más lejos con las capacidades de variaciones.El sitio web debe estar disponible en alemán y en inglés.
En el pie de página de la página principal, coloqué algunos enlaces codificados como esto:
<a href="/Authenticate.aspx">Login</a>
<a href="/imprint">Imprint</a>
<a href="/disclaimer">Disclaimer</a>
y quiero que reconstruyan dinámicamente en mi sitio de variaciones como este para el idioma alemán:
<a href="/de/...">Login</a>
<a href="/de/...">Imprint</a>
<a href="/de/...">Disclaimer</a>
o esto para ingles:
<a href="/en/...">Login</a>
<a href="/en/...">Imprint</a>
<a href="/en/...">Disclaimer</a>
¿Hay una variable que pueda colocar frente a los enlaces en mi página maestra?¿O un método para obtener el idioma actual?
Estaba pensando en algo como esto:
<a href="{Locale}/login">...</a>
<a href="$language/imprint...">...</a>
<a href="getLanguage()/disclaimer">...</a>
No soy un codificador ASP.NET, así que realmente no sé cómo averiguar el idioma.Agradecería que alguien pudiera ayudarme.
Solución 2
I solved the problem with another method: I used SharePoints own Javascript variable - _spPageContextInfo - see: _spPageContextInfo is your new best friend !
With "currentCultureName" I could use the language name as a variable to compare to the target language and to expand my PageLayout with custom links, compliant to my variations settings.
The Code could look like this:
$(document).ready(function() {
$language = _spPageContextInfo.currentCultureName;
// If it's german, I'll get german links
if ($language == "de-DE") {
$('.footer').html('<a href="/de/kontakt/">Kontakt</a>');
} else {
// And if not, it will target to the english page
$('.footer').html('<a href="/en/contact">Contact</a>');
}
});
Otros consejos
You could use the SPWeb.Locale property of the current context (as in SPContext.Current.Web.Locale
) to glean this information.
If you look at the Remarks section of the CultureInfo Class description on MSDN it will explain this.
A simple example would be:
<a href="/<%= SPContext.Current.Web.Locale.TwoLetterISOLanguageName %>/Login.aspx">...</a>