Skip to content

Commit

Permalink
Set preferred language in generator; get available languages in gpkg …
Browse files Browse the repository at this point in the history
…connector
  • Loading branch information
gacarrillor committed Oct 25, 2024
1 parent 2c1c773 commit 4c6d789
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
8 changes: 7 additions & 1 deletion modelbaker/dbconnector/db_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ def set_preferred_translation(self, lang: str) -> bool:
"""
Returns whether the preferred translation language was successfully set
"""
if len(lang) == 2:
if len(lang) == 2 and lang != "__":
self._lang = lang
return True

Expand All @@ -417,6 +417,12 @@ def get_translation_handling(self) -> tuple[bool, str]:
"""
return False, ""

def get_available_languages(self) -> list[str]:
"""
Returns a list of available languages in the t_ili2db_nls table.
"""
return []


class DBConnectorError(Exception):
"""This error is raised when DbConnector could not connect to database.
Expand Down
22 changes: 18 additions & 4 deletions modelbaker/dbconnector/gpkg_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,7 @@ def _get_tables_info(self):
interlis_joins = ""
tr_enabled, lang = self.get_translation_handling()
if tr_enabled:
self.new_message.emit(
Qgis.Info,
f"Getting tables info with preferred language {lang}.",
)
self.stdout.emit(f"Getting tables info with preferred language {lang}.")

if self.metadata_exists():
interlis_fields = """p.setting AS kind_settings,
Expand Down Expand Up @@ -1213,3 +1210,20 @@ def set_ili2db_sequence_value(self, value):

def get_translation_handling(self) -> tuple[bool, str]:
return self._table_exists(GPKG_NLS_TABLE) and self._lang != "", self._lang

def get_available_languages(self):
if not self._table_exists(GPKG_NLS_TABLE):
return []

cursor = self.conn.cursor()
cursor.execute(
"""SELECT DISTINCT
lang
FROM "{}";
""".format(
GPKG_NLS_TABLE
)
)
records = cursor.fetchall()
cursor.close()
return [record["lang"] for record in records]
3 changes: 3 additions & 0 deletions modelbaker/generator/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def __init__(
mgmt_uri: Optional[str] = None,
consider_basket_handling: bool = False,
optimize_strategy: OptimizeStrategy = OptimizeStrategy.NONE,
preferred_language: str = "",
) -> None:
"""
Creates a new Generator objects.
Expand All @@ -76,6 +77,8 @@ def __init__(
self.basket_handling = consider_basket_handling and self.get_basket_handling()
self.optimize_strategy = optimize_strategy

self._db_connector.set_preferred_translation(preferred_language)

self._additional_ignored_layers = (
[]
) # List of layers to ignore set by 3rd parties
Expand Down

0 comments on commit 4c6d789

Please sign in to comment.