Skip to content

Error if reserved message keys are mixed with unreserved keys#320

Merged
nicksnyder merged 11 commits intomainfrom
mixedkeyserror
Oct 13, 2024
Merged

Error if reserved message keys are mixed with unreserved keys#320
nicksnyder merged 11 commits intomainfrom
mixedkeyserror

Conversation

@nicksnyder
Copy link
Copy Markdown
Owner

Makes it an error to provide data that mixes reserved message keys with unreserved ones. Previously the unreserved keys would be ignored, but this caused surprising behavior where if someone added a message that had a key with a reserved word, it would silently break the whole translation file. This change turns that situation into an error.

Resolves #209

@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 4, 2024

Codecov Report

Attention: Patch coverage is 92.18750% with 5 lines in your changes missing coverage. Please review.

Project coverage is 75.73%. Comparing base (0a3a706) to head (09888bc).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
i18n/message.go 94.33% 2 Missing and 1 partial ⚠️
i18n/parse.go 81.81% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #320      +/-   ##
==========================================
+ Coverage   74.90%   75.73%   +0.82%     
==========================================
  Files          20       20              
  Lines        1634     1677      +43     
==========================================
+ Hits         1224     1270      +46     
+ Misses        347      344       -3     
  Partials       63       63              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@nicksnyder nicksnyder marked this pull request as ready for review October 13, 2024 01:55
@nicksnyder nicksnyder merged commit af5be8c into main Oct 13, 2024
@nicksnyder nicksnyder deleted the mixedkeyserror branch October 13, 2024 05:38
@andriiberezhynskyi
Copy link
Copy Markdown

andriiberezhynskyi commented Jan 28, 2025

Hello @nicksnyder
I did this change more than 3 years ago:

-      "descr": "{{if .DeliveryTime}}Livraison estimée : {{.DeliveryTime}} jours{{end}}",
+      "descr": {
+        "other": "{{if .DeliveryTime}}Livraison estimée : {{.DeliveryTime}} jours{{end}}",
+        "leftDelim": "<<",
+        "rightDelim": ">>"
+      },

I don't fully remember how it all works but it was a workaround to support golang templating {{}} inside translations. The problem is that this pr introduces a breaking change and all of a sudden I have this error:

reserved keys [other] mixed with unreserved keys [leftDelim rightDelim]

How do I fix this problem?

UPDATE. Created the issue #357

@bep bep mentioned this pull request Oct 18, 2025
bep pushed a commit to gohugoio/go-i18n that referenced this pull request Oct 18, 2025
…yder#320)

Makes it an error to provide data that mixes reserved message keys with
unreserved ones. Previously the unreserved keys would be ignored, but
this caused surprising behavior where if someone added a message that
had a key with a reserved word, it would silently break the whole
translation file. This change turns that situation into an error.

Resolves nicksnyder#209
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

Successfully merging this pull request may close these issues.

translation file with key "id" leads LoadMessageFile to fail silently

2 participants