In QGIS 3 under Project|Project Properties|Variables you find a Global called qgis_locale
wich you can use to automatically determine the column used for labeling. Use the following expression for this:
eval('"name_' || @qgis_locale || '"')
The @
references a variable, the string concatenation "name_' || @qgis_locale || '"
will give you the column (here: "name_el"
) and eval()
does evaluate the column name to its value.
Since in QGIS 2 there is no such variable, so one might define a custom function to get the first two letters of the user locale (en
, de
) and use this for the expression that automatically selects the column to get labels from:
"""
Define new functions using @qgsfunction. feature and parent must always be the
last args. Use args=-1 to pass a list of values as arguments
"""
from qgis.core import *
from qgis.gui import *
from PyQt4.QtCore import QSettings
@qgsfunction(args='auto', group='Locale')
def getLocale(feature, parent):
return QSettings().value("locale/userLocale")[0:2]
The expression then changes to
eval('"name_' || getLocale() || '"')
With this the language of the labels in the map should directly depend on the users locale settings.