-
Notifications
You must be signed in to change notification settings - Fork 7
added option to use a suffix for singular forms #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -60,6 +60,7 @@ class I18NextOptions with Diagnosticable { | |
| this.nestingPrefix, | ||
| this.nestingSuffix, | ||
| this.nestingSeparator, | ||
| this.singularSuffix, | ||
| this.pluralSuffix, | ||
| this.missingKeyHandler, | ||
| this.missingInterpolationHandler, | ||
|
|
@@ -87,6 +88,7 @@ class I18NextOptions with Diagnosticable { | |
| nestingPrefix: r'$t(', | ||
| nestingSuffix: ')', | ||
| nestingSeparator: ',', | ||
| singularSuffix: 'singular', | ||
| pluralSuffix: 'plural', | ||
| missingKeyHandler: null, | ||
| missingInterpolationHandler: null, | ||
|
|
@@ -138,14 +140,26 @@ class I18NextOptions with Diagnosticable { | |
| /// Defaults to '.'. | ||
| final String? keySeparator; | ||
|
|
||
| /// [singularSuffix] is used for the pluralization mechanism. | ||
| /// | ||
| /// Defaults to 'singular' and is used for simple pluralization rules. | ||
| /// | ||
| /// For example, in english where it only has singular or plural forms: | ||
| /// | ||
| /// ``` | ||
| /// "friend_singular": "A friend" | ||
| /// "friend_plural": "{{count}} friends" | ||
| /// ``` | ||
|
Comment on lines
+145
to
+152
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here too, the default should be null to maintain the existing behavior |
||
| final String? singularSuffix; | ||
|
|
||
| /// [pluralSuffix] is used for the pluralization mechanism. | ||
| /// | ||
| /// Defaults to 'plural' and is used for simple pluralization rules. | ||
| /// | ||
| /// For example, in english where it only has singular or plural forms: | ||
| /// | ||
| /// ``` | ||
| /// "friend": "A friend" | ||
| /// "friend_singular": "A friend" | ||
|
Comment on lines
-148
to
+162
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ✂️ keep default behavior docs |
||
| /// "friend_plural": "{{count}} friends" | ||
| /// ``` | ||
| final String? pluralSuffix; | ||
|
|
@@ -256,6 +270,7 @@ class I18NextOptions with Diagnosticable { | |
| contextSeparator: other.contextSeparator ?? contextSeparator, | ||
| pluralSeparator: other.pluralSeparator ?? pluralSeparator, | ||
| keySeparator: other.keySeparator ?? keySeparator, | ||
| singularSuffix: other.singularSuffix ?? singularSuffix, | ||
| pluralSuffix: other.pluralSuffix ?? pluralSuffix, | ||
| interpolationPrefix: other.interpolationPrefix ?? interpolationPrefix, | ||
| interpolationSuffix: other.interpolationSuffix ?? interpolationSuffix, | ||
|
|
@@ -294,6 +309,7 @@ class I18NextOptions with Diagnosticable { | |
| String? contextSeparator, | ||
| String? pluralSeparator, | ||
| String? keySeparator, | ||
| String? singularSuffix, | ||
| String? pluralSuffix, | ||
| String? interpolationPrefix, | ||
| String? interpolationSuffix, | ||
|
|
@@ -320,6 +336,7 @@ class I18NextOptions with Diagnosticable { | |
| contextSeparator: contextSeparator ?? this.contextSeparator, | ||
| pluralSeparator: pluralSeparator ?? this.pluralSeparator, | ||
| keySeparator: keySeparator ?? this.keySeparator, | ||
| singularSuffix: singularSuffix ?? this.singularSuffix, | ||
| pluralSuffix: pluralSuffix ?? this.pluralSuffix, | ||
| interpolationPrefix: interpolationPrefix ?? this.interpolationPrefix, | ||
| interpolationSuffix: interpolationSuffix ?? this.interpolationSuffix, | ||
|
|
@@ -365,6 +382,7 @@ class I18NextOptions with Diagnosticable { | |
| nestingPrefix, | ||
| nestingSuffix, | ||
| nestingSeparator, | ||
| singularSuffix, | ||
| pluralSuffix, | ||
| missingKeyHandler, | ||
| missingInterpolationHandler, | ||
|
|
@@ -394,6 +412,7 @@ class I18NextOptions with Diagnosticable { | |
| other.nestingPrefix == nestingPrefix && | ||
| other.nestingSuffix == nestingSuffix && | ||
| other.nestingSeparator == nestingSeparator && | ||
| other.singularSuffix == singularSuffix && | ||
| other.pluralSuffix == pluralSuffix && | ||
| other.missingKeyHandler == missingKeyHandler && | ||
| other.missingInterpolationHandler == missingInterpolationHandler && | ||
|
|
@@ -422,6 +441,7 @@ class I18NextOptions with Diagnosticable { | |
| ..add(StringProperty('nestingPrefix', nestingPrefix)) | ||
| ..add(StringProperty('nestingSuffix', nestingSuffix)) | ||
| ..add(StringProperty('nestingSeparator', nestingSeparator)) | ||
| ..add(StringProperty('singularSuffix', singularSuffix)) | ||
| ..add(StringProperty('pluralSuffix', pluralSuffix)) | ||
| ..add(StringProperty('missingKeyHandler', missingKeyHandler?.toString())) | ||
| ..add( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,8 +14,15 @@ class PluralResolver { | |
| final separator = options.pluralSeparator ?? '_'; | ||
|
|
||
| if (_ruleUsesSimpleSuffixes(rule)) { | ||
| final suffix = options.pluralSuffix ?? 'plural'; | ||
| return index == 0 ? '' : '$separator$suffix'; | ||
| late final String suffix; | ||
|
|
||
| if (index == 0) { | ||
| suffix = options.singularSuffix ?? 'singular'; | ||
| } else { | ||
| suffix = options.pluralSuffix ?? 'plural'; | ||
| } | ||
|
|
||
| return suffix.isEmpty ? '' : '$separator$suffix'; | ||
|
Comment on lines
-17
to
+25
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. since the base options are merged, we could do the following here to simplify this expression:
this is what I mean: final suffix = index == 0 ? options.singularSuffix : options.pluralSuffix;
return suffix == null || suffix.isEmpty ? '' : '$separator$suffix'; |
||
| } else { | ||
| return '$separator$index'; | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to avoid breaking localization changes, the default should still be maintained