electricitymaps / electricitymaps-contrib

A real-time visualisation of the CO2 emissions of electricity consumption
https://app.electricitymaps.com
GNU Affero General Public License v3.0
3.4k stars 914 forks source link

Grammar for localizations #3869

Closed LaosPL closed 2 years ago

LaosPL commented 2 years ago

Error message: [sprintf] expecting number but found string Url: https://app.electricitymap.org/zone/PL

That is an error I get quite often

madsnedergaard commented 2 years ago

Hey @LaosPL, thanks for reporting this :) Could you provide some more context, like the following:

theundefined commented 2 years ago

Same issue here. device - linux ubuntu 22.04 browser: Wersja 100.0.4896.127 (Oficjalna wersja) (64-bitowa) language: pl.

After refresh sometimes is ok, but after few minutes of "clicking" i still have: image

In console there are more details:

breadcrumbs.ts:117 TypeError: [sprintf] expecting number but found string
    at sprintf.js:62:27
    at o (sprintf.js:26:16)
    at a (sprintf.js:30:24)
    at j (translation.js:9:12)
    at __ (translation.js:20:32)
    at countrypanelexchangetooltip.jsx:45:18
    at da (react-dom.production.min.js:154:98)
    at As (react-dom.production.min.js:259:456)
    at Mu (react-dom.production.min.js:230:22)
    at Ou (react-dom.production.min.js:229:362)
    at xu (react-dom.production.min.js:223:216)
    at react-dom.production.min.js:121:115
    at e.unstable_runWithPriority (scheduler.production.min.js:18:437)
    at Xi (react-dom.production.min.js:120:325)
    at Ji (react-dom.production.min.js:121:61)
    at Yi (react-dom.production.min.js:120:496)
    at lt (react-dom.production.min.js:285:209)
    at On (react-dom.production.min.js:83:253)
    at Mn (react-dom.production.min.js:84:470)
    at An (react-dom.production.min.js:84:98)
    at e.unstable_runWithPriority (scheduler.production.min.js:18:437)
    at Cn (react-dom.production.min.js:82:330)
    at HTMLDocument.sentryWrapped (helpers.ts:90:17) Object
mobuchowski commented 2 years ago

I have pretty similar error.

Firefox 100.0.1 Mac OS 12.04 (MBP 14' 2021) Language PL

This generally happens after changing few zones.

Error message: [sprintf] expecting number but found string
Url: https://app.electricitymap.org/zone/FR
TypeError: [sprintf] expecting number but found string
    s sprintf.js:62
    a sprintf.js:26
    o sprintf.js:30
    D translation.js:9
    __ translation.js:20
    co countrypanelexchangetooltip.jsx:47
    React 6
    unstable_runWithPriority scheduler.production.min.js:19
    React 7
    unstable_runWithPriority scheduler.production.min.js:19
    Xt React

Object { componentStack: "\n    in Unknown\n    in Connect(Component)\n    in div\n    in styled.div\n    in Unknown\n    in Connect(Component)\n    in div\n    in styled.div\n    in div\n    in styled.div\n    in Unknown\n    in Connect(Component)\n    in div\n    in Unknown\n    in Connect(Component)\n    in t\n    in t\n    in div\n    in styled.div\n    in Unknown\n    in Connect(Component)\n    in Jc\n    in div\n    in div\n    in Unknown\n    in Connect(Component)\n    in t\n    in c\n    in Suspense" }
errorboundary.jsx:49:12
    componentDidCatch errorboundary.jsx:49
    React 4
    unstable_runWithPriority scheduler.production.min.js:19
    React 4
    unstable_runWithPriority scheduler.production.min.js:19
    React 7
    unstable_runWithPriority scheduler.production.min.js:19
    Xt React
madsnedergaard commented 2 years ago

Thanks all, the issue here is that in the Polish translation it's expecting that there's always a number, while it can also a string ("?"). While looking into it, it seems like the text is also formatted/written differently than in English - could someone help me with new translations? :)

English

Screenshot 2022-05-24 at 16 25 00
    "electricityComesFrom": "<b>%1$s %%</b> of electricity available in <img id=\"country-flag\"></img> <b>%2$s</b> comes from %3$s",
    "emissionsComeFrom": "<b>%1$s %%</b> of emissions from electricity available in <img id=\"country-flag\"></img> <b>%2$s</b> come from %3$s",
    "electricityStoredUsing": "<b>%1$s %%</b> of electricity available in <img id=\"country-flag\"></img> <b>%2$s</b> is stored using %3$s",
    "emissionsStoredUsing": "<b>%1$s %%</b> of emissions from electricity available in <img id=\"country-flag\"></img> <b>%2$s</b> are stored using %3$s",
    "electricityExportedTo": "<b>%1$s %%</b> of electricity available in <img id=\"country-flag\"></img> <b>%2$s</b> is exported to <img id=\"country-exchange-flag\"></img> <b>%3$s</b>",
    "emissionsExportedTo": "<b>%1$s %%</b> of emissions from electricity available in <img id=\"country-flag\"></img> <b>%2$s</b> are exported to <img id=\"country-exchange-flag\"></img> <b>%3$s</b>",
    "electricityImportedFrom": "<b>%1$s %%</b> of electricity available in <img id=\"country-flag\"></img> <b>%2$s</b> is imported from <img id=\"country-exchange-flag\"></img> <b>%3$s</b>",
    "emissionsImportedFrom": "<b>%1$s %%</b> of emissions from electricity available in <img id=\"country-flag\"></img> <b>%2$s</b> are imported from <img id=\"country-exchange-flag\"></img> <b>%3$s</b>",

Current translations (that should be changed so format matches the English one above)

Screenshot 2022-05-24 at 16 25 09
    "electricityComesFrom": "<img id=\"country-flag\"></img> <b>%2$s</b>: produkcja %3$s tworzy <b>%1$s %%</b> energii elektrycznej",
    "emissionsComeFrom": "<img id=\"country-flag\"></img> <b>%2$s</b>: produkcja %3$s tworzy <b>%1$s %%</b> emisji",
    "electricityStoredUsing": "<img id=\"country-flag\"></img> <b>%2$s</b>: %3$s przetrzymywują <b>%1$s %%</b> energii elektrycznej",
    "emissionsStoredUsing": "<img id=\"country-flag\"></img> <b>%2$s</b>: %3$s przetrzymywują <b>%1$s %%</b> emisji",
    "electricityExportedTo": "<img id=\"country-flag\"></img> <b>%2$s</b>: <b>%1$s %%</b> energii elektrycznej jest eksportowane do <img id=\"country-exchange-flag\"></img> <b>%3$s</b>",
    "emissionsExportedTo": "<img id=\"country-flag\"></img> <b>%2$s</b>: <b>%1$s %%</b> emisji jest eksportowane do <img id=\"country-exchange-flag\"></img> <b>%3$s</b>",
    "electricityImportedFrom": "<img id=\"country-flag\"></img> <b>%2$s</b>: <b>%1$s %%</b> energii elektrycznej jest importowane z <img id=\"country-exchange-flag\"></img> <b>%3$s</b>",
    "emissionsImportedFrom": "<img id=\"country-flag\"></img> <b>%2$s</b>: <b>%1$s %%</b> emisji jest importowane z <img id=\"country-exchange-flag\"></img> <b>%3$s</b>",
jarek commented 2 years ago

While looking into it, it seems like the text is also formatted/written differently than in English - could someone help me with new translations? :)

I think the different formatting is done on purpose to make the imperfect grammar less jarring.

Grammatically, the subject of "30% of electricity available in X is imported from Y" is the electricity (or the "30% of electricity").

In Polish, if we wanted to use the form "30% of electricity available in X is imported from Y", both country name nouns should be declined, and they should use different grammatical cases. My Polish grammar terminology is rusty, but as far as I can tell, I think X should be in locative case and Y should be in genitive case.

Correctly written, this would be something like "30% energii elektrycznej dostępnej w Portugalii jest importowane z Hiszpanii". The declined forms aren't always the same.

Electricity Map doesn't currently have separate localizations for country names in distinct grammar cases. If we did, it would be something like:

country name nominative: Portugalia, Hiszpania, Niemcy, Francja, Polska
country name in: Portugalii, Hiszpanii, Niemczech, Francji, Polsce
country name from/to: Portugalii, Hiszpanii, Niemiec, Francji, Polski

By rearranging the localization to essentially take out one of the country names out of the sentence with the format "X: 30% energii elektrycznej jest importowane z Y", we have one of the country names in nominative, and thus one of the country names is not wrong grammatically. Same thing is done for electricityComesFrom and similar keys.

If you would be willing to update the rendering script to use country name in or from as appropriate if provided in the localization file, and fallback to country name nominative if not set, we can make updates to the Polish localization file to match.

Somewhat related, the Polish localization of electricityComesFrom is in format "Country X: S-ish production creates 30% of electricity" where "S-ish" is the source in adjective form (essentially "coal-ish", "hydro-ish") to avoid needing two different cases for nouns of energy sources: nominative "coal" and "from coal".

madsnedergaard commented 2 years ago

Oh okay, that makes somewhat sense 😅 I suggest we leave it like this then for now and close this issue again - think we might end up addressing it with historical view anyway :)