Skip to content

Commit

Permalink
Merge pull request #11359 from camptocamp/lingva
Browse files Browse the repository at this point in the history
Use a maintained fork of lingua
  • Loading branch information
sbrunner authored Sep 4, 2024
2 parents 89647f1 + 811073c commit f35334f
Show file tree
Hide file tree
Showing 29 changed files with 68 additions and 43 deletions.
4 changes: 2 additions & 2 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
!admin/requirements.txt
!admin/setup.cfg
!admin/setup.py
!admin/lingua.cfg
!admin/lingva.cfg
!scripts/clone_schema.sql
!scripts/extract-messages.js
!vars.yaml
!.tx
!lingua.cfg
!lingva.cfg
**/*~
**/*.pyc
**/*.pyo
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ RUN make --makefile=dependencies.mk dependencies
COPY bin/ /usr/bin/
COPY scripts/ scripts/
COPY geoportal/c2cgeoportal_geoportal/scaffolds/ geoportal/c2cgeoportal_geoportal/scaffolds/
COPY build.mk lingua.cfg ./
COPY build.mk lingva.cfg ./

RUN make --makefile=build.mk build \
&& mkdir -p 'geoportal/c2cgeoportal_geoportal/scaffolds/update/{{cookiecutter.project}}/CONST_create_template/geoportal/interfaces/' \
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2011-2023, Camptocamp SA
# Copyright (c) 2011-2024, Camptocamp SA
# All rights reserved.

# Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -30,7 +30,7 @@
from typing import Any, Optional

import yaml
from lingua.extractors import Extractor, Message
from lingva.extractors import Extractor, Message


class GeomapfishConfigExtractor(Extractor): # type: ignore
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions admin/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@
install_requires=install_requires,
entry_points={
"paste.app_factory": ["main = c2cgeoportal_admin:main"],
"lingua.extractors": [
"geomapfish-admin-config = c2cgeoportal_admin.lib.lingua_extractor:GeomapfishConfigExtractor",
"lingva.extractors": [
"geomapfish-admin-config = c2cgeoportal_admin.lib.lingva_extractor:GeomapfishConfigExtractor",
],
},
)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2022-2023, Camptocamp SA
# Copyright (c) 2022-2024, Camptocamp SA
# All rights reserved.

# Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -33,7 +33,7 @@
import yaml
from c2c.template.config import config as configuration

from c2cgeoportal_admin.lib.lingua_extractor import GeomapfishConfigExtractor
from c2cgeoportal_admin.lib.lingva_extractor import GeomapfishConfigExtractor

GMF_CONFIG = """
vars:
Expand All @@ -50,7 +50,7 @@

class TestGeomapfishConfigExtractor:
@patch(
"c2cgeoportal_admin.lib.lingua_extractor.open",
"c2cgeoportal_admin.lib.lingva_extractor.open",
mock_open(read_data=GMF_CONFIG),
)
def test_extract_config(self):
Expand Down
2 changes: 1 addition & 1 deletion bin/update-po
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ OWNER=$1:$2
shift 2

# shellcheck disable=SC2046
pot-create --config="geoportal/lingua-client${SUFFIX}.cfg" --width=110 \
pot-create --config="geoportal/lingva-client${SUFFIX}.cfg" --width=110 \
--output="geoportal/${PACKAGE}_geoportal/locale/${PACKAGE}_geoportal-client${SUFFIX}.pot" \
$(find "geoportal/${PACKAGE}_geoportal/static-ngeo/js/apps/" -type f -name '*.html.ejs') \
$(find "geoportal/${PACKAGE}_geoportal/static-ngeo/js/" -type f -name '*.js') \
Expand Down
4 changes: 2 additions & 2 deletions build.mk
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,12 @@ geoportal/c2cgeoportal_geoportal/scaffolds%advance_update/{{cookiecutter.project
cp -r $< $@

geoportal/c2cgeoportal_geoportal/locale/c2cgeoportal_geoportal.pot: \
lingua.cfg $(SRC_FILES)
lingva.cfg $(SRC_FILES)
mkdir --parent $(dir $@)
pot-create --width=110 --config=$< --keyword=_ --output=$@ $(SRC_FILES)

admin/c2cgeoportal_admin/locale/c2cgeoportal_admin.pot: \
admin/lingua.cfg $(ADMIN_SRC_FILES)
admin/lingva.cfg $(ADMIN_SRC_FILES)
mkdir --parent $(dir $@)
pot-create --width=110 --config=$< --keyword=_ --output=$@ $(ADMIN_SRC_FILES) ./geoportal/c2cgeoportal_geoportal/scaffolds/update/{{cookiecutter.project}}/geoportal/CONST_vars.yaml

Expand Down
2 changes: 1 addition & 1 deletion doc/integrator/https.rst
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ Local certificate checks
------------------------

Certain c2cgeoportal features open a http session to your c2cgeoportal services,
for example the ``checker`` or the ``lingua_extractor``.
for example the ``checker`` or the ``lingva_extractor``.
If you are running your server in https and wish to disable certificate checks in these
connections, you can achieve this by adding the following configuration element to your ``vars`` file:

Expand Down
2 changes: 1 addition & 1 deletion doc/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docker/config/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docker/qgisserver/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
from c2c.template.config import config
from defusedxml.minidom import parseString
from geoalchemy2.types import Geometry
from lingua.extractors import Extractor, Message
from lingva.extractors import Extractor, Message
from mako.lookup import TemplateLookup
from mako.template import Template
from owslib.wms import WebMapService
Expand Down Expand Up @@ -732,7 +732,7 @@ def _import_layer_attributes(

def _build_url(self, url: Url) -> tuple[Url, dict[str, str], dict[str, Any]]:
hostname = url.hostname
host_map = self.config.get("lingua_extractor", {}).get("host_map", {})
host_map = self.config.get("lingva_extractor", {}).get("host_map", {})
if hostname in host_map:
map_ = host_map[hostname]
if "netloc" in map_:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ build: $(BUILD_RULES)
PO_FILES = $(addprefix $(PACKAGE)_geoportal/locale/, $(addsuffix /LC_MESSAGES/$(PACKAGE)_geoportal-server.po, $(LANGUAGES)))

.INTERMEDIATE: $(PACKAGE)_geoportal/locale/$(PACKAGE)_geoportal-server.pot
$(PACKAGE)_geoportal/locale/$(PACKAGE)_geoportal-server.pot: lingua-server.cfg $(SRC_FILES)
$(PACKAGE)_geoportal/locale/$(PACKAGE)_geoportal-server.pot: lingva-server.cfg $(SRC_FILES)
mkdir --parent $(dir $@)
[ -z "$(SRC_FILES)" ] || pot-create --width=110 --config=$< --keyword=_ --output=$@ $(SRC_FILES)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ ENV CONFIG_VARS sqlalchemy.url sqlalchemy.pool_recycle sqlalchemy.pool_size sqla
reset_password fulltextsearch global_headers headers authorized_referers hooks stats db_chooser \
dbsessions urllogin host_forward_host headers_whitelist headers_blacklist \
smtp c2c.base_path welcome_email \
lingua_extractor interfaces_config interfaces devserver_url api authentication intranet metrics pdfreport \
lingva_extractor interfaces_config interfaces devserver_url api authentication intranet metrics pdfreport \
vector_tiles i18next main_ogc_server

COPY . /tmp/config/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,9 @@ upgrade_files:
- action: remove
paths:
- geoportal/tools/extract-messages.js
- action: move
from: geoportal/lingua-server.cfg
to: geoportal/lingva-server.cfg
- action: move
from: geoportal/lingua-client.cfg
to: geoportal/lingva-client.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ mapping:
sequence:
- *map

lingua_extractor:
lingva_extractor:
type: map
mapping:
host_map:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -972,7 +972,7 @@ vars:
pdfreport:
print_url: '{PRINT_URL}'

lingua_extractor: {}
lingva_extractor: {}

content_security_policy_main_default_src_extra: ''
# Google Maps uses map.google.com and map.googleapis.com
Expand Down
10 changes: 5 additions & 5 deletions geoportal/c2cgeoportal_geoportal/views/i18n.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

import pyramid.request
import pyramid.response
from lingua.extract import ( # strip_linenumbers,
from lingva.extract import ( # strip_linenumbers,
ExtractorOptions,
POEntry,
create_catalog,
Expand All @@ -40,8 +40,8 @@
no_duplicates,
read_config,
)
from lingua.extractors import get_extractor, register_extractors
from lingua.extractors.babel import register_babel_plugins
from lingva.extractors import get_extractor, register_extractors
from lingva.extractors.babel import register_babel_plugins
from pyramid.httpexceptions import HTTPFound, HTTPInternalServerError
from pyramid.view import view_config

Expand Down Expand Up @@ -78,15 +78,15 @@ def localepot(request: pyramid.request.Request) -> pyramid.response.Response:
sources += ["/etc/geomapfish/config.yaml", "/app/development.ini"]

# The following code is a modified version of the main function of this file:
# https://github.com/wichert/lingua/blob/master/src/lingua/extract.py
# https://github.com/wichert/lingva/blob/master/src/lingva/extract.py

global _INITIALIZED
if not _INITIALIZED:
register_extractors()
register_babel_plugins()
_INITIALIZED = True

with open("/app/lingua-client.cfg", encoding="utf-8") as config_file:
with open("/app/lingva-client.cfg", encoding="utf-8") as config_file:
read_config(config_file)
_INITIALIZED = True

Expand Down
2 changes: 1 addition & 1 deletion geoportal/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Fiona
GeoAlchemy2
geojson
isodate # WMST support
lingua
lingva
Mako
OWSLib>=0.6.0
papyrus
Expand Down
8 changes: 4 additions & 4 deletions geoportal/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@
"c2cgeoportal_advance_create = c2cgeoportal_geoportal.scaffolds:TemplateAdvanceCreate",
"c2cgeoportal_advance_update = c2cgeoportal_geoportal.scaffolds:TemplateAdvanceUpdate",
],
"lingua.extractors": [
"geomapfish-theme = c2cgeoportal_geoportal.lib.lingua_extractor:GeomapfishThemeExtractor",
"geomapfish-config = c2cgeoportal_geoportal.lib.lingua_extractor:GeomapfishConfigExtractor",
"geomapfish-angular = c2cgeoportal_geoportal.lib.lingua_extractor:GeomapfishAngularExtractor",
"lingva.extractors": [
"geomapfish-theme = c2cgeoportal_geoportal.lib.lingva_extractor:GeomapfishThemeExtractor",
"geomapfish-config = c2cgeoportal_geoportal.lib.lingva_extractor:GeomapfishConfigExtractor",
"geomapfish-angular = c2cgeoportal_geoportal.lib.lingva_extractor:GeomapfishAngularExtractor",
],
"plaster.loader_factory": [
"c2cgeoportal=c2cgeoportal_geoportal.lib.loader:Loader",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2020-2023, Camptocamp SA
# Copyright (c) 2020-2024, Camptocamp SA
# All rights reserved.

# Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -29,7 +29,7 @@

from unittest.mock import Mock, patch

from c2cgeoportal_geoportal.lib.lingua_extractor import GeomapfishAngularExtractor
from c2cgeoportal_geoportal.lib.lingva_extractor import GeomapfishAngularExtractor


class TestGeomapfishAngularExtractor:
Expand All @@ -40,7 +40,7 @@ def test_extract_desktop_html_ejs(self):
}

with patch(
"c2cgeoportal_geoportal.lib.lingua_extractor.subprocess.check_output",
"c2cgeoportal_geoportal.lib.lingva_extractor.subprocess.check_output",
return_value=b'[["desktop.html.ejs:34","Theme:"]]',
):
options = Mock()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2020-2023, Camptocamp SA
# Copyright (c) 2020-2024, Camptocamp SA
# All rights reserved.

# Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -34,7 +34,7 @@
from c2c.template.config import config as configuration
from tests.functional import setup_common as setup_module

from c2cgeoportal_geoportal.lib.lingua_extractor import GeomapfishConfigExtractor
from c2cgeoportal_geoportal.lib.lingva_extractor import GeomapfishConfigExtractor

GMF_CONFIG = """
vars:
Expand Down Expand Up @@ -128,7 +128,7 @@ def test_data(dbsession, transact):
@pytest.mark.usefixtures("test_data")
class TestGeomapfishConfigExtractor:
@patch(
"c2cgeoportal_geoportal.lib.lingua_extractor.open",
"c2cgeoportal_geoportal.lib.lingva_extractor.open",
mock_open(read_data="vars:"),
)
def test_extract_config(self, settings, dbsession):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@

import pytest

from c2cgeoportal_geoportal.lib.lingua_extractor import GeomapfishThemeExtractor
from c2cgeoportal_geoportal.lib.lingva_extractor import GeomapfishThemeExtractor


class TestGeomapfishThemeExtractor:
def extract(self):
extractor = GeomapfishThemeExtractor()
extractor.config = {"lingua_extractor": {}}
extractor.config = {"lingva_extractor": {}}

options = Mock()
options.keywords = []
Expand Down
File renamed without changes.
21 changes: 20 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ setuptools = "74.0.0"
Babel = "2.14.0" # i18n
beautifulsoup4 = "4.12.3" # admin tests
Jinja2 = "3.1.4" # c2c.template
lingua = "4.15.0" # i18n
lingva = "5.0.3" # i18n
PasteScript = "3.6.0" # geoportal pcreate
polib = "1.2.0" # i18n
pykwalify = "1.8.0" # Validate config
Expand Down

0 comments on commit f35334f

Please sign in to comment.