Skip to content

Conversation

@shenlong-tanwen
Copy link
Member

Description

Adds a new translation helper with strict typing. The existing translation extension is copied over to the generated file so as to reduce the number of imports required.

// Get translation instance (marks widget for rebuild on locale change)
final t = Translations.of(context);
String a = t.about;

// BuildContext extension shorthand
String b = context.t.about;

// Nested access for nested JSON keys
String c = t.admin.backup_settings;

// Typed parameters extracted from {placeholders}
String d = t.active_count(count: 5);
String e = t.admin.cleared_jobs(job: "thumbnails");

A static non-context accessor is also added to the generated code and can be used with the following syntax. The syntax is intentionally longer to penalise the usage of it

StaticTranslations.instance.uploading_media

Copy link
Member

@jrasm91 jrasm91 left a comment

Choose a reason for hiding this comment

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

Very cool

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants