Update: 2026-06-14 05:48:58
This commit is contained in:
@@ -83,17 +83,55 @@ class CountryLogic {
|
||||
|
||||
/// Helper to format phone using the current country in box.
|
||||
static String formatCurrentCountryPhone(String phone) {
|
||||
String cleanPhone = phone.replaceAll(RegExp(r'[ \-\(\)]'), '').trim();
|
||||
if (cleanPhone.startsWith('+963') || cleanPhone.startsWith('00963')) {
|
||||
String cleanPhone = phone.replaceAll(RegExp(r'[ \-\(\)\+]'), '').trim();
|
||||
|
||||
// 1. Explicit International Code Detection
|
||||
if (cleanPhone.startsWith('00963')) {
|
||||
cleanPhone = cleanPhone.replaceFirst('00963', '963');
|
||||
}
|
||||
if (cleanPhone.startsWith('00962')) {
|
||||
cleanPhone = cleanPhone.replaceFirst('00962', '962');
|
||||
}
|
||||
if (cleanPhone.startsWith('0020')) {
|
||||
cleanPhone = cleanPhone.replaceFirst('0020', '20');
|
||||
}
|
||||
|
||||
if (cleanPhone.startsWith('963')) {
|
||||
return formatPhone(cleanPhone, 'Syria');
|
||||
}
|
||||
if (cleanPhone.startsWith('+20') || cleanPhone.startsWith('0020')) {
|
||||
if (cleanPhone.startsWith('962')) {
|
||||
return formatPhone(cleanPhone, 'Jordan');
|
||||
}
|
||||
if (cleanPhone.startsWith('20')) {
|
||||
return formatPhone(cleanPhone, 'Egypt');
|
||||
}
|
||||
if (cleanPhone.startsWith('+962') || cleanPhone.startsWith('00962')) {
|
||||
|
||||
// 2. Local/National Format Detection by Country-Specific Mobile Prefixes
|
||||
// Jordan: 07x / 7x (9 national digits)
|
||||
if (cleanPhone.startsWith('07') && cleanPhone.length == 10) {
|
||||
return formatPhone(cleanPhone, 'Jordan');
|
||||
}
|
||||
if (cleanPhone.startsWith('7') && cleanPhone.length == 9) {
|
||||
return formatPhone(cleanPhone, 'Jordan');
|
||||
}
|
||||
|
||||
// Syria: 09x / 9x (9 national digits)
|
||||
if (cleanPhone.startsWith('09') && cleanPhone.length == 10) {
|
||||
return formatPhone(cleanPhone, 'Syria');
|
||||
}
|
||||
if (cleanPhone.startsWith('9') && cleanPhone.length == 9) {
|
||||
return formatPhone(cleanPhone, 'Syria');
|
||||
}
|
||||
|
||||
// Egypt: 01x (10 national digits) / 1x (9 national digits)
|
||||
if (cleanPhone.startsWith('01') && cleanPhone.length == 11) {
|
||||
return formatPhone(cleanPhone, 'Egypt');
|
||||
}
|
||||
if (cleanPhone.startsWith('1') && cleanPhone.length == 10) {
|
||||
return formatPhone(cleanPhone, 'Egypt');
|
||||
}
|
||||
|
||||
// 3. Fallback: Default to current user's country code saved in box
|
||||
final country = box.read(BoxName.countryCode) ?? 'Syria';
|
||||
return formatPhone(cleanPhone, country);
|
||||
}
|
||||
|
||||
30
siro_driver/lib/controller/functions/translate_helper.dart
Normal file
30
siro_driver/lib/controller/functions/translate_helper.dart
Normal file
@@ -0,0 +1,30 @@
|
||||
import 'dart:convert';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
class TranslateHelper {
|
||||
static Future<String> translateText(String text, String targetLang) async {
|
||||
if (text.isEmpty) return text;
|
||||
try {
|
||||
final url = Uri.parse(
|
||||
'https://translate.googleapis.com/translate_a/single?client=gtx&sl=auto&tl=$targetLang&dt=t&q=${Uri.encodeComponent(text)}'
|
||||
);
|
||||
final response = await http.get(url);
|
||||
if (response.statusCode == 200) {
|
||||
final decoded = jsonDecode(response.body);
|
||||
if (decoded != null && decoded is List && decoded.isNotEmpty && decoded[0] is List) {
|
||||
final List parts = decoded[0];
|
||||
String translated = '';
|
||||
for (var part in parts) {
|
||||
if (part is List && part.isNotEmpty) {
|
||||
translated += part[0].toString();
|
||||
}
|
||||
}
|
||||
return translated;
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
// Fallback to original text on any exception
|
||||
}
|
||||
return text;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user