Vaibhav Surve 99902e743c Flutter application
- Created generated_plugin_registrant.cc and generated_plugin_registrant.h to manage plugin registration.
- Added generated_plugins.cmake for plugin configuration in CMake.
- Implemented CMakeLists.txt for the Windows runner, defining build settings and dependencies.
- Created Runner.rc for application resources including versioning and icons.
- Developed flutter_window.cpp and flutter_window.h to manage the Flutter window lifecycle.
- Implemented main.cpp as the entry point for the Windows application.
- Added resource.h for resource definitions.
- Included app icon in resources.
- Created runner.exe.manifest for application settings.
- Developed utils.cpp and utils.h for console management and command line argument handling.
- Implemented win32_window.cpp and win32_window.h for high DPI-aware window management.
2025-04-17 12:30:38 +05:30

82 lines
2.4 KiB
Dart

import 'dart:convert';
import 'dart:developer';
import 'package:marco/helpers/services/localizations/language.dart';
import 'package:flutter/services.dart';
import 'package:get/get_utils/src/extensions/string_extensions.dart';
import 'package:shared_preferences/shared_preferences.dart';
class Translator {
static Map<String, String>? _localizedStrings;
static Future<bool> changeLanguage(Language language) async {
try {
String jsonString = await rootBundle
.loadString('assets/lang/${language.locale.languageCode}.json');
Map<String, dynamic> jsonLanguageMap = json.decode(jsonString);
_localizedStrings = jsonLanguageMap.map((key, value) {
return MapEntry(key, value.toString());
});
return true;
} catch (e) {
log(e.toString());
}
return false;
}
// called from every screens which needs a localized text
static String translate(String text) {
if (_localizedStrings != null) {
String? value = _localizedStrings![text];
return value ?? autoTranslate(text);
}
return autoTranslate(text);
}
static String autoTranslate(String text) {
// log("You need to translate this text : " + text);
at(text);
try {
List<String> texts = text.split("_");
StringBuffer stringBuffer = StringBuffer();
for (String singleText in texts) {
stringBuffer
.write("${singleText[0].toUpperCase()}${singleText.substring(1)} ");
}
String result = stringBuffer.toString();
return result.substring(0, result.length - 1);
} catch (err) {
return text;
}
}
static Future<void> at(String t) async {
// print("at");
SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
var data = sharedPreferences.getStringList('test_tr') ?? [];
var set = data.toSet();
set.add(t);
sharedPreferences.setStringList('test_tr', set.toList());
}
static clearTrans() async {
SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
await sharedPreferences.remove('test_tr');
}
static getUnTrans() async {
SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
var data = sharedPreferences.getStringList('test_tr') ?? [];
var set = data.toSet();
String text = "";
for (var value in set.toList()) {
var p = value.replaceAll("_", " ");
p = p.capitalize!;
text += ('"$value": "$p",\n');
}
log(text);
}
}