Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ Localized strings can be accessed through `AppLocalizations.of(context)`

Requirements:

- Add `sprintf: ^4.0.2` to the `dependencies` section of `pubspec.yaml`
- Add `sprintf: ^6.0.0` to the `dependencies` section of `pubspec.yaml`
- Add `AppLocalizationsDelegate()` to `localizationsDelegates` of the app widget constructor
- Specify supported localizations in `supportedLocales` of the app widget constructor
- (Recommended) Add `DefaultIntlLocaleDelegate()` to `localizationsDelegates` of the app widget constructor. This will make `intl`-dependent formatters use currently selected locale.
Expand Down
16 changes: 8 additions & 8 deletions platforms/flutter.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (flutter) Header(args *goloc.HeaderArgs) string {
part of 'localizations.dart';

class AppLocalizations%s implements AppLocalizations {
final AppLocalizations fallback;
final AppLocalizations? fallback;

AppLocalizations%s(this.fallback);

Expand All @@ -48,18 +48,18 @@ class AppLocalizations%s implements AppLocalizations {
func (flutter) LocalizedString(args *goloc.LocalizedStringArgs) string {
if len(args.FormatArgs) > 0 {
fArgs := buildFormatArgsList(args.FormatArgs, nil)
return fmt.Sprintf(" String %s(%s) => sprintf(\"%s\", [%s]);\n", args.Key, fArgs, args.Value, fArgs)
return fmt.Sprintf(" String? %s(%s) => sprintf(\"%s\", [%s]);\n", args.Key, fArgs, args.Value, fArgs)
} else {
return fmt.Sprintf(" String get %s => \"%s\";\n", args.Key, args.Value)
return fmt.Sprintf(" String? get %s => \"%s\";\n", args.Key, args.Value)
}
}

func (flutter) FallbackString(args *goloc.LocalizedStringArgs) string {
if len(args.FormatArgs) > 0 {
fArgs := buildFormatArgsList(args.FormatArgs, nil)
return fmt.Sprintf(" String %s(%s) => fallback?.%s(%s);\n", args.Key, fArgs, args.Key, fArgs)
return fmt.Sprintf(" String? %s(%s) => fallback?.%s(%s);\n", args.Key, fArgs, args.Key, fArgs)
} else {
return fmt.Sprintf(" String get %s => fallback?.%s;\n", args.Key, args.Key)
return fmt.Sprintf(" String? get %s => fallback?.%s;\n", args.Key, args.Key)
}
}

Expand Down Expand Up @@ -101,7 +101,7 @@ import 'package:sprintf/sprintf.dart';
%s
abstract class AppLocalizations {
static AppLocalizations of(BuildContext context) {
return Localizations.of<AppLocalizations>(context, AppLocalizations);
return Localizations.of<AppLocalizations>(context, AppLocalizations)!;
}

%s}
Expand Down Expand Up @@ -138,11 +138,11 @@ class AppLocalizationsDelegate extends LocalizationsDelegate<AppLocalizations> {
for _, key := range args.Localizations.SortedKeys() {
fArgs := args.FormatArgs[key]
if len(fArgs) <= 0 {
str := fmt.Sprintf(" String get %s;\n", key)
str := fmt.Sprintf(" String? get %s;\n", key)
locBuilder.WriteString(str)
} else {
typedArgsStr := buildFormatArgsList(fArgs, args.Formats)
str := fmt.Sprintf(" String %s(%s);\n", key, typedArgsStr)
str := fmt.Sprintf(" String? %s(%s);\n", key, typedArgsStr)
locBuilder.WriteString(str)
}
}
Expand Down