Skip to content

Latest commit

 

History

History
70 lines (49 loc) · 3.17 KB

README.md

File metadata and controls

70 lines (49 loc) · 3.17 KB

Developed with 💚 by netglade

ci native_fcm_strings license: MIT style: netglade analysis Discord


Native FCM Strings Plugin

This Flutter plugin provides a simple way to access localized strings from native Android and iOS resources, such as strings.xml (Android) and .strings files (iOS). It allows Flutter applications to retrieve the correct localized strings based on the system language settings, ensuring consistency across both native and Flutter parts of the app.

Features

  • Access Android's strings.xml resources based on the system language.
  • Access iOS .strings resources (via .lproj folders) based on the system language.
  • Use the same localization files used by native Android and iOS notifications, avoiding duplication of localization files for Flutter.
  • Supports dynamic language switching based on device locale.

Installation

  1. Add the plugin to your pubspec.yaml file:

    dependencies:
      native_fcm_strings: ^1.0.0
  2. Run flutter pub get to install the package.

Usage

Accessing Native Strings in Flutter

import 'package:native_fcm_strings/native_fcm_strings.dart';

// Example usage
String localizedTitle = await NativeStrings.getTranslatedString(key: 'notification_title', locArgs: ['John', 'Doe']); // Returns: Message from John to Doe
String localizedBody = await NativeStrings.getTranslatedString(key: 'notification_body', locArgs: ['John', 'Doe']); // Returns: Message from John to Doe

This will retrieve the localized string from the appropriate native resources (strings.xml for Android or .strings for iOS) based on the current device locale.

Android Setup

Ensure that your strings.xml files are properly placed in language-specific folders under res/values (e.g., res/values-en, res/values-cs).

Arguments in localized strings has to be in format %1$s, e.g Message from %1$s to %2$s.

iOS Setup

Ensure that your .strings files are placed under language-specific .lproj folders (e.g., en.lproj, cs.lproj).

Arguments in localized strings has to be in format %1$s, e.g Message from %@ to %@.

👏 Contributing

Your contributions are always welcome! Feel free to open pull request.