setTranslations static method
Future<void>
setTranslations({
- required String fileNameOrPath,
- String? packageName,
- required dynamic flyCallback(
- FlyResponse response
Initializes customized translations for the MirrorFly platform.
This method allows you to provide a localized translation JSON file to be used within the SDK. The file can be loaded either from the main app’s asset bundle or from an external Flutter package.
Parameters:
fileNameOrPath
: The name or path of the translation JSON file.- If only a file name is provided (e.g.,
"en.json"
), the plugin assumes it is located atassets/i18n/en.json
. You must declare this path under theassets
section of yourpubspec.yaml
. - If a relative path is provided (e.g.,
"your_file_path/en.json"
), the plugin will use that path directly. This must also be declared underassets
in yourpubspec.yaml
.
- If only a file name is provided (e.g.,
packageName
: (Optional) The name of the package if the translation file resides in an external package. In this case, the file will be resolved frompackages/<packageName>/<fileNameOrPath>
. You must declare the asset path under theassets
section of that package’spubspec.yaml
.flyCallback
: A callback function that receives a FlyResponse object indicating whether the translation initialization was successful.
Example:
Mirrorfly.setTranslations(
fileNameOrPath: "en.json",
packageName: "your_package_name", // optional
flyCallback: (response) {
if (response.isSuccess) {
print("Translations updated successfully");
} else {
print("Failed to update translations: ${response.message}");
}
},
);
Implementation
static Future<void> setTranslations({
required String fileNameOrPath,
String? packageName,
required Function(FlyResponse response) flyCallback,
}) {
return FlyChatFlutterPlatform.instance.setTranslations(
fileNameOrPath: fileNameOrPath,
packageName: packageName,
callback: flyCallback,
);
}