ueman / feedback

A simple widget for getting better feedback.
https://pub.dev/packages/feedback
378 stars 92 forks source link

Spanish language support #283

Closed as-stefit closed 4 months ago

as-stefit commented 4 months ago

In my app I'm using spanish language, would be nice to have it as well :)

ueman commented 4 months ago

I don't speak Spanish, so I'm leaving this for someone who does.

TijnvandenEijnde commented 4 months ago

You can create a custom class, this way you can add any language you want. This is the class I am using in my application. I am using easy_localization for the translations.

import 'package:easy_localization/easy_localization.dart';
import 'package:feedback/feedback.dart';
import 'package:flutter/material.dart';

class CustomFeedbackLocalizations implements FeedbackLocalizations {
  @override
  String get draw => tr('feedBackPage.draw');

  @override
  String get feedbackDescriptionText => tr('feedBackPage.description');

  @override
  String get navigate => tr('feedBackPage.navigate');

  @override
  String get submitButtonText => tr('feedBackPage.submit');
}

class CustomFeedbackLocalizationsDelegate
    extends GlobalFeedbackLocalizationsDelegate {
  @override
  // ignore: overridden_fields
  final supportedLocales = <Locale, FeedbackLocalizations>{
    const Locale('de'): CustomFeedbackLocalizations(),
    const Locale('en'): CustomFeedbackLocalizations(),
    const Locale('es'): CustomFeedbackLocalizations(),
    const Locale('fr'): CustomFeedbackLocalizations(),
    const Locale('nl'): CustomFeedbackLocalizations(),
    const Locale('pt'): CustomFeedbackLocalizations(),
    const Locale('ru'): CustomFeedbackLocalizations(),
    const Locale('uk'): CustomFeedbackLocalizations(),
  };
}

In your BetterFeedback widget you can use the class like so:

return BetterFeedback(
  localizationsDelegates: [
    ...context.localizationDelegates,
    CustomFeedbackLocalizationsDelegate(),
  ],
  localeOverride: context.locale,
  child: MaterialApp(
    locale: context.locale,
    localizationsDelegates: context.localizationDelegates,
    supportedLocales: context.supportedLocales,
  ),
),

It could be possible that I have forgotten something, please let me know if you need some help @as-stefit .