Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow generating a report in a new language, even if not configured for that city #420

Closed
carlhiggs opened this issue May 1, 2024 · 1 comment

Comments

@carlhiggs
Copy link
Member

carlhiggs commented May 1, 2024

Currently reports can only be generated for cities for which a language has been defined in their region configuration file.

If an attempt is made to generate report in a language that is not configured for a city that otherwise has a translation (validated or not) in the report configuration file, the following error occurs:

# python
Python 3.12.3 | packaged by conda-forge | (main, Apr 15 2024, 18:38:13) [GCC 12.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ghsci
>>> r = ghsci.example()

Example study region loaded.  Loading the configured example region as a variable 'r' by running 'r = ghsci.example()' is equivalent to running 'r = ghsci.Region('example_ES_Las_Palmas_2023')' in the Python console.  To proceed with analysis using the 'r' region variable, one can enter 'r.analysis()'.  Once analysis has completed, once can then enter 'r.generate()' to generate resources.  For more information, run 'ghsci.help()'.

>>> r.generate_report(language='French')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/ghsci/process/subprocesses/ghsci.py", line 853, in generate_report
    generate_report_for_language(
  File "/home/ghsci/process/subprocesses/_utils.py", line 176, in generate_report_for_language
    phrases = r.get_phrases(language)
              ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ghsci/process/subprocesses/ghsci.py", line 1506, in get_phrases
    phrases['city_name'] = city_details['languages'][language]['name']
                           ~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^

The above error is basically saying, this language hasn't been configured for this study region.

There is a pragmatic reason for this requirement, that translation of a study region name into a new language needs to be done on a case by case basis, and is therefore best defined by users within the configuration for that study region (which may be a city, but could be a neighbourhood, or any other arbitrary area, technically -- so the translated name may not be predictable a priori).

However, it would be helpful if a user could generate a report in another language without first configuring it, by supplying some default (e.g. English) along with advice on how to formally update this by modifying the configuration file.

This would provide users with a template to paste into their configuration file for the new language, and also make generating draft reports for validation of new languages (that don't depend on specific city names) easier by not requiring formal configuration. So, even though French or any other language may not be configured for the example region, it could be nice to quickly generate a report to demonstrate what it might look like. For my purposes right now, generating reports for translation validation for an arbitrary and expanding number of new languages to support #417, this would be helpful and speed things up.

carlhiggs added a commit that referenced this issue May 1, 2024
… using fallback defaults for city name, country name and language, as per #420
@carlhiggs
Copy link
Member Author

I modified the r.get_phrases() to include a check that language is present in configuration file, and if not, to provide fallback defaults using English for city name, country and summary, but otherwise display using a translated language if it is available.

This results in output like the following when attempting to generate a report (followed by those reports being generated):

# python
Python 3.12.3 | packaged by conda-forge | (main, Apr 15 2024, 18:38:13) [GCC 12.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ghsci
>>> r = ghsci.example()

Example study region loaded.  Loading the configured example region as a variable 'r' by running 'r = ghsci.example()' is equivalent to running 'r = ghsci.Region('example_ES_Las_Palmas_2023')' in the Python console.  To proceed with analysis using the 'r' region variable, one can enter 'r.analysis()'.  Once analysis has completed, once can then enter 'r.generate()' to generate resources.  For more information, run 'ghsci.help()'.

>>> r.generate_report('French')
'French' has not yet been configured for this study region.  This requires the addition of specific details, including the name and country of this study region in this language.  The following template will be used to generate a demonstration report now, and may be inserted into the reporting languages section of the configuration file and updated for full support of this French; please translate as required using a text editor:


        French:
            country: Spain
            name: Las Palmas
            summary: After reviewing results for your city, provide a contextualised summary in French

@carlhiggs carlhiggs changed the title All generating a report in a new language, even if not configured for that city Allow generating a report in a new language, even if not configured for that city May 2, 2024
@carlhiggs carlhiggs mentioned this issue May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant