Skip to content
This repository has been archived by the owner on Jul 12, 2023. It is now read-only.

Add i18n framework #1107

Merged
merged 1 commit into from
Nov 17, 2020
Merged

Add i18n framework #1107

merged 1 commit into from
Nov 17, 2020

Conversation

sethvargo
Copy link
Member

Adds a few default translations for demonstration

Fixes #1083

Release Note

Add internationalization framework (no supported translations yet)

Adds a few default translations for demonstration
@googlebot googlebot added the cla: yes Auto: added by CLA bot when all committers have signed a CLA. label Nov 17, 2020
@@ -35,7 +35,7 @@
</div>
{{end}}

<h1>Create verification code</h1>
<h1>{{t $.locale "create-verification-code"}}</h1>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not in love with having to pass in the locale, but template functions aren't mutable after creation.

// translate accepts a message printer (populated by middleware) and prints the
// translated text for the given key. If the printer is nil, an error is
// returned.
func translate(l *gotext.Locale, key string, vars ...interface{}) (string, error) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is important because the default behavior is to just return the empty string, which is a pretty difficult-to-debug failure. I'd like the template execution to fail on missing i18n keys.

"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"

msgid "create-verification-code"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to come up with a better grouping for these. I thought about header.create-verification-code or something to make it clearer.

msgstr "Diagnóstico"

msgid "dates"
msgstr "Fechas"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice spanish

"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is this Plural-Forms doing?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing right now. But if you ever had a sentence like:

There were %d bananas

You'd want to define:

  • =0 "There were no bananas"
  • =1 "There was 1 banana"
  • >1 "There were %d bananas"

That's what plurals do. It's part of the gettext standard: https://www.gnu.org/software/gettext/manual/html_node/Translating-plural-forms.html

@google-oss-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: sethvargo, whaught

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@google-oss-robot google-oss-robot merged commit ed8db22 into main Nov 17, 2020
@google-oss-robot google-oss-robot deleted the sethvargo/i18n branch November 17, 2020 15:16
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 18, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla: yes Auto: added by CLA bot when all committers have signed a CLA.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

i18n
4 participants