remote localization files added
parent
f929bd9017
commit
0eb9ec11d3
@ -0,0 +1,6 @@
|
|||||||
|
<svg width="56" height="56" viewBox="0 0 56 56" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<rect width="56" height="56" rx="28" fill="white"/>
|
||||||
|
<rect width="56" height="56" rx="28" fill="white"/>
|
||||||
|
<rect x="0.5" y="0.5" width="55" height="55" rx="27.5" stroke="#2E3039" stroke-opacity="0.13" stroke-dasharray="2 2"/>
|
||||||
|
<path fill-rule="evenodd" clip-rule="evenodd" d="M28 18.25C28.4142 18.25 28.75 18.5858 28.75 19V26.25H36C36.4142 26.25 36.75 26.5858 36.75 27C36.75 27.4142 36.4142 27.75 36 27.75H28.75V35C28.75 35.4142 28.4142 35.75 28 35.75C27.5858 35.75 27.25 35.4142 27.25 35V27.75H20C19.5858 27.75 19.25 27.4142 19.25 27C19.25 26.5858 19.5858 26.25 20 26.25H27.25V19C27.25 18.5858 27.5858 18.25 28 18.25Z" fill="#161616" stroke="#2E3039" stroke-width="0.5" stroke-linecap="round" stroke-linejoin="round"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 835 B |
@ -0,0 +1,27 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
import 'dart:io';
|
||||||
|
import 'dart:ui';
|
||||||
|
import 'package:easy_localization/easy_localization.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
|
import 'package:path_provider/path_provider.dart';
|
||||||
|
|
||||||
|
class RemoteFileLoader extends AssetLoader {
|
||||||
|
@override
|
||||||
|
Future<Map<String, dynamic>?> load(String path, Locale locale) async {
|
||||||
|
final directory = await getApplicationDocumentsDirectory();
|
||||||
|
|
||||||
|
// easy_localization uses toLanguageTag() which gives 'en-US' or 'ar-SA'
|
||||||
|
final fileName = "${locale.toLanguageTag()}.json";
|
||||||
|
final file = File("${directory.path}/$fileName");
|
||||||
|
|
||||||
|
if (await file.exists()) {
|
||||||
|
final String jsonString = await file.readAsString();
|
||||||
|
return jsonDecode(jsonString);
|
||||||
|
} else {
|
||||||
|
// If the download failed or hasn't happened yet, load from local assets
|
||||||
|
// path is the 'path' property from the EasyLocalization widget
|
||||||
|
final localData = await rootBundle.loadString('$path/$fileName');
|
||||||
|
return jsonDecode(localData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,35 @@
|
|||||||
|
import 'dart:io';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:hmg_patient_app_new/core/api_consts.dart';
|
||||||
|
import 'package:http/http.dart' as http;
|
||||||
|
import 'package:path_provider/path_provider.dart';
|
||||||
|
|
||||||
|
class TranslationService {
|
||||||
|
// Replace with your actual hosting URL
|
||||||
|
static final String baseUrl = ApiConsts.googleCloudStorageENTranslationFileBaseURL;
|
||||||
|
|
||||||
|
static Future<void> downloadTranslations() async {
|
||||||
|
final directory = await getApplicationDocumentsDirectory();
|
||||||
|
|
||||||
|
// Ensure these match your locale codes exactly (en-US, ar-SA)
|
||||||
|
List<String> files = ["en-US.json", "ar-SA.json"];
|
||||||
|
|
||||||
|
for (String fileName in files) {
|
||||||
|
try {
|
||||||
|
String url = "$baseUrl/$fileName";
|
||||||
|
debugPrint(url);
|
||||||
|
// final response = await http.get(Uri.parse("$baseUrl/$fileName"));
|
||||||
|
final response = await http.get(Uri.parse(url));
|
||||||
|
|
||||||
|
if (response.statusCode == 200) {
|
||||||
|
final file = File("${directory.path}/$fileName");
|
||||||
|
await file.writeAsBytes(response.bodyBytes);
|
||||||
|
} else {
|
||||||
|
print("Failed to download $fileName: Status ${response.statusCode}");
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
print("Network error while downloading $fileName: $e");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue