CodeForPhilly / chime

COVID-19 Hospital Impact Model for Epidemics
https://codeforphilly.github.io/chime/
MIT License
205 stars 151 forks source link

Implement i18n functions #159

Closed kochizufan closed 4 years ago

kochizufan commented 4 years ago

Hi,

I didn't realize that the main development is ongoing under this repository not pennsignals, so I submitted i18n PR to pennsignals by mistake.

I can do some modifications to my code and re-submit it to this repository if need, but I want to ask:

  1. I18n function is still needed?
  2. My approach for resource file is like this, do you think this is reasonable?
    • Short statements without line breaks: setting the entire statement to both the resource's key and value
    • Long statements with line breaks: the key is the beginning of the statement, abbreviated with ..., and the value is the entire statement.
  3. I can implement i18n function, but because of my lack of streamlit knowledge, I have no idea how to implement language-switching function. Does someone have ideas?
quinn-dougherty commented 4 years ago

thanks @kochizufan! let's stay in touch. Streamlit is really restrictive, i don't have a background in i18n, but I don't know if we can get streamlit to support it.

We haven't talked a lot about translation, but it's a really good idea.

we're prototyping an alternative to streamlit. the best way to stay tuned is to join our slack https://codeforphilly.org/chat?channel=covid19-chime-penn

kochizufan commented 4 years ago

Hi @quinn-dougherty ,

Thank you for a reply, I already joined Slack, but sorry, I may/will overlook many things cause I'm not a native English speaker...

According to your last reply, I understand that you may change the program framework from streamlit to something else. If so, it may be too early to discuss i18n features.

If so, how about starting with translating a document? https://code-for-philly.gitbook.io/chime/ If you give me read-only access to the raw source code of this document site, I will translate it into Japanese. https://code4history.gitbook.io/chime/ We will make a Japanese version here. This is also useful for me to understand CHIME's medical background.

How do you think about this?

mishmosh commented 4 years ago

@kochizufan We'd very much appreciate your help to translate the usage guide!

Unfortunately we edit this on GitBook so don't have a typical repo with markdown (.md) files to share/fork. It looks like GitBook doesn't export markdown, either.

However, you should be able to mimic the chapter structure from https://code-for-philly.gitbook.io/chime/ pretty easily in Gitbook.

Please keep us posted on your progress and thank you again.

ecsmyth commented 4 years ago

User Story

As a non-English speaking hospital administrator, I want to use CHIME to support capacity planning, so that my hospital is better prepared to address the COVID-19 pandemic.

While the U.S. is struggling to prepare, and much of the current media focus is on Italy with its mortality rate near 10 percent, dozens of other countries are struggling to cope with their own COVID-19 outbreaks. The per capita mortality rate in Spain is nearing that of Italy. Countries like Turkey and Ecuador have only recently identified their 100th case domestically, but are reporting doubling rates worse than Italy. While the WHO acknowledges English as the lingua franca for public health, there is still a disconnect that impacts non-English speaking policy makers and public health officials as well.

Possible Acceptance Criteria

Recommended Out of scope for this issue

kochizufan commented 4 years ago

I already created i18n branch on https://github.com/code4history/chime-1/tree/i18n and keeping in touch with latest update of develop branch.

My branch still have a issue (I can't fix CI test failure) so I can't make pull request, but I don't mind if the other person start i18n work, then I can help him or her by providing part of my work (Japanese resources https://github.com/code4history/chime-1/blob/i18n/locales/ja.yml , etc.)

And I found some i18n difficulties in current chime codes, I share them here:

ckoerber commented 4 years ago

Let me copy a part of a conversation I had with @ecsmyth related to the dash version.

Q:

Is there a reason behind your template-based approach vs an i18n library like gettext or python-fluent?

A:

The main reason for the templetated approach is to factorize layout from language content. The hope is that this makes it easier for others to help out (without parsing the dash specific files). Regarding translations, I’d support any other solution which helps out systematically. If we did not miss a spot, there is only the content property you would have to adjust to translate everything. This function reads the template and returns either plain text or a str-str dict from template. So if you translate here instead of reading a different template, you should be done. Please let me know if that helps or if you have other questions

TL;DR: We could translate the dash app by either translating all files by hand (which does not require any programming expertise, one has to translate files in the templates directory) or by using external tools and wrapping one function call.

kochizufan commented 4 years ago

I already checked dash-based code from the recent "develop" branch (Unfortunately, it couldn't be run in my environment for some reason, it caused some error and stopped). I think its approach to i18n is reasonable and I can agree with it. Once it become mainstream, I can provide Japanese resources.

One question, does dash-based chime replace streamlit-based chime? Or do they continue to be developed in parallel?

kochizufan commented 4 years ago

For reference:

The result of running dash-based app on my local environment: (hash of commit: 00d41f3386642f932728532c05390dcdc2ed7fb6 [00d41f3])

$python src/dash_app.py
Traceback (most recent call last):
  File "/Users/kokogiko/github/chime/src/chime_dash/app/components/base.py", line 90, in html
    self._html = self.get_html()
  File "/Users/kokogiko/github/chime/src/chime_dash/app/components/sidebar.py", line 98, in get_html
    element = create_number_input(idx, data, self.content, self.defaults)
  File "/Users/kokogiko/github/chime/src/chime_dash/app/utils/templates.py", line 102, in create_number_input
    idx, defaults, min_val=data.get("min", None), max_val=data.get("max", None)
  File "/Users/kokogiko/github/chime/src/chime_dash/app/utils/templates.py", line 156, in _get_default_values
    val = defaults.region.susceptible
AttributeError: 'Regions' object has no attribute 'susceptible'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/kokogiko/github/chime/src/chime_dash/app/components/base.py", line 90, in html
    self._html = self.get_html()
  File "/Users/kokogiko/github/chime/src/chime_dash/app/components/__init__.py", line 72, in get_html
    children=self.components["sidebar"].html,
  File "/Users/kokogiko/github/chime/src/chime_dash/app/components/base.py", line 92, in html
    raise HTMLComponentError(self, error)
chime_dash.app.components.base.HTMLComponentError: AttributeError->'Regions' object has no attribute 'susceptible' while rendering HTML component <chime_dash.app.components.sidebar.Sidebar object at 0x10857e210>

Data:
language: en
 -localization_file: sidebar.yml
 -content: {'current_hospitalized': 'Currently Hospitalized COVID-19 Patients', 'doubling_time': 'Doubling time before social distancing (days)', 'relative_contact_rate': 'Social distancing (% reduction in social contact)', 'hospitalized_rate': 'Hospitalization %(total infections)', 'icu_rate': 'ICU %(total infections)', 'ventilated_rate': 'Ventilated %(total infections)', 'hospitalized_los': 'Hospital Length of Stay', 'icu_los': 'ICU Length of Stay', 'ventilated_los': 'Vent Length of Stay', 'market_share': 'Hospital Market Share (%)', 'susceptible': 'Regional Population', 'known_infected': 'Currently Known Regional Infections (only used to compute detection rate - does not change projections)', 'n_days': 'Number of days to project', 'as_date': 'Present results as dates', 'max_y_axis': 'Set the Y-axis on graphs to a static', 'max_y_axis_value': 'Maximal y-axis value (leave blank for no max value)', 'show_tables': 'Show tables with data', 'show_tool_details': 'Show more info about this tool', 'show_additional_projections': 'Show additional projections'}
 -defaults: Constants(population_default: 4119405, known_infected: 510)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "src/dash_app.py", line 32, in <module>
    app.layout = body.html
  File "/Users/kokogiko/github/chime/src/chime_dash/app/components/base.py", line 92, in html
    raise HTMLComponentError(self, error)
chime_dash.app.components.base.HTMLComponentError: HTMLComponentError->AttributeError->'Regions' object has no attribute 'susceptible' while rendering HTML component <chime_dash.app.components.sidebar.Sidebar object at 0x10857e210>

Data:
language: en
 -localization_file: sidebar.yml
 -content: {'current_hospitalized': 'Currently Hospitalized COVID-19 Patients', 'doubling_time': 'Doubling time before social distancing (days)', 'relative_contact_rate': 'Social distancing (% reduction in social contact)', 'hospitalized_rate': 'Hospitalization %(total infections)', 'icu_rate': 'ICU %(total infections)', 'ventilated_rate': 'Ventilated %(total infections)', 'hospitalized_los': 'Hospital Length of Stay', 'icu_los': 'ICU Length of Stay', 'ventilated_los': 'Vent Length of Stay', 'market_share': 'Hospital Market Share (%)', 'susceptible': 'Regional Population', 'known_infected': 'Currently Known Regional Infections (only used to compute detection rate - does not change projections)', 'n_days': 'Number of days to project', 'as_date': 'Present results as dates', 'max_y_axis': 'Set the Y-axis on graphs to a static', 'max_y_axis_value': 'Maximal y-axis value (leave blank for no max value)', 'show_tables': 'Show tables with data', 'show_tool_details': 'Show more info about this tool', 'show_additional_projections': 'Show additional projections'}
 -defaults: Constants(population_default: 4119405, known_infected: 510)
 while rendering HTML component <chime_dash.app.components.Body object at 0x10857e1d0>

Data:
language: en
 -localization_file: None
 -content: {}
 -defaults: Constants(population_default: 4119405, known_infected: 510)
ckoerber commented 4 years ago

I already checked dash-based code from the recent "develop" branch

Sorry my bad. The dash development currently takes place in the dash branch. Launching the app should work there.

does dash-based chime replace streamlit-based chime? Or do they continue to be developed in parallel?

We are currently developing both in parallel but to my knowledge, it is intended to phase out steamlit in favor of dash with the next major release.

BrianThomasRoss commented 4 years ago

Closed with latest merge