You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
1.2 KiB
Dart
36 lines
1.2 KiB
Dart
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");
|
|
}
|
|
}
|
|
}
|
|
}
|