diff --git a/internalsdk/session_model.go b/internalsdk/session_model.go index d1d4965b8..d393c2f91 100644 --- a/internalsdk/session_model.go +++ b/internalsdk/session_model.go @@ -188,9 +188,13 @@ func (s *SessionModel) InvokeMethod(method string, arguments minisql.Values) (*m } case SESSION_MODEL_METHOD_SET_LOCAL: local := arguments.Get(0) - err := setLanguage(s.baseModel, local.String()) + value, err := extractLangValueFromJSON(local.String()) if err != nil { return nil, err + } + langErr := setLanguage(s.baseModel, value) + if langErr != nil { + return nil, err } else { return minisql.NewValueBool(true), nil } @@ -436,8 +440,6 @@ func getBandwidthLimit(m *baseModel) (string, error) { } func (s *SessionModel) Locale() (string, error) { - // For now just send back english by default - // Once have machisim but to dyanmic locale, err := s.baseModel.db.Get(LANG) if err != nil { return "", err @@ -446,6 +448,8 @@ func (s *SessionModel) Locale() (string, error) { } func setLanguage(m *baseModel, langCode string) error { + log.Debugf("Lang debugger got value %v", langCode) + pathdb.Mutate(m.db, func(tx pathdb.TX) error { pathdb.Put[string](tx, LANG, langCode, "") return nil diff --git a/internalsdk/utils.go b/internalsdk/utils.go index 7032127f5..9a4ea086c 100644 --- a/internalsdk/utils.go +++ b/internalsdk/utils.go @@ -63,7 +63,22 @@ func putFromJson(jsonString string, db pathdb.DB) error { if !ok { return log.Errorf("Invalid value for type string: %v", value) } - pathdb.Put[string](tx, key, actualValue, "") + + if key == "lang" { + // Check if lang is already added or not + lang, err := pathdb.Get[string](tx, LANG) + if err != nil { + return err + } + if lang != "" { + pathdb.Put[string](tx, key, lang, "") + } else { + pathdb.Put[string](tx, key, actualValue, "") + } + } else { + pathdb.Put[string](tx, key, actualValue, "") + } + case minisql.ValueTypeInt: // Convert value to string and put it actualValue, ok := value.(int) @@ -111,3 +126,19 @@ func BytesToFloat64LittleEndian(b []byte) (float64, error) { bits := binary.LittleEndian.Uint64(b) return math.Float64frombits(bits), nil } + +type Lang struct { + Lang string `json:"lang"` +} + +func extractLangValueFromJSON(localStr string) (string, error) { + var langObj Lang + err := json.Unmarshal([]byte(localStr), &langObj) + if err != nil { + return "", err + } + if langObj.Lang == "" { + return "", fmt.Errorf("lang value not found") + } + return langObj.Lang, nil +} diff --git a/ios/Podfile b/ios/Podfile index a30b9b8dd..89788fb35 100644 --- a/ios/Podfile +++ b/ios/Podfile @@ -45,8 +45,16 @@ target 'LanternTests' do pod 'Toast-Swift', '~> 5.0.1' end +#post_install do |installer| +# installer.pods_project.targets.each do |target| +# flutter_additional_ios_build_settings(target) +# end +#end post_install do |installer| installer.pods_project.targets.each do |target| flutter_additional_ios_build_settings(target) + target.build_configurations.each do |config| + config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '11.0' + end end end diff --git a/ios/Podfile.lock b/ios/Podfile.lock index b8bbe9367..57b65fb68 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -314,6 +314,6 @@ SPEC CHECKSUMS: wakelock: d0fc7c864128eac40eba1617cb5264d9c940b46f webview_flutter_wkwebview: 2e2d318f21a5e036e2c3f26171342e95908bd60a -PODFILE CHECKSUM: 757318b04676b684e713ddd4ea4c00406ab62433 +PODFILE CHECKSUM: 0cfe0e959396ac6aad61f61d0b82005395de9d66 COCOAPODS: 1.11.3 diff --git a/ios/Runner.xcodeproj/project.pbxproj b/ios/Runner.xcodeproj/project.pbxproj index f1b713d82..097ab2c47 100644 --- a/ios/Runner.xcodeproj/project.pbxproj +++ b/ios/Runner.xcodeproj/project.pbxproj @@ -1115,8 +1115,6 @@ FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", "$(PROJECT_DIR)/InternalFrameworks", - "$(PROJECT_DIR)/InternalFrameworks/Pods_DatabaseFramework.framework", - "$(PROJECT_DIR)/InternalFrameworks/DatabaseFramework.framework", ); INFOPLIST_FILE = Runner/Info.plist; INFOPLIST_KEY_CFBundleDisplayName = Lantern; diff --git a/lib/account/language.dart b/lib/account/language.dart index 86634a6a2..5dc1a97bd 100644 --- a/lib/account/language.dart +++ b/lib/account/language.dart @@ -14,11 +14,11 @@ class Language extends StatelessWidget { body: sessionModel .language((BuildContext context, String currentLang, Widget? child) { // Splint language by just code - final countryCode= currentLang.split('_')[0]; + final countryCode= currentLang; return ListView.builder( itemCount: languages.length, itemBuilder: (BuildContext context, int index) { - var lang = languages[index].split('_')[0]; + var lang = languages[index]; return RadioListTile( activeColor: pink4, contentPadding: const EdgeInsetsDirectional.all(0), diff --git a/lib/app.dart b/lib/app.dart index 8cfdad2df..758c7c123 100644 --- a/lib/app.dart +++ b/lib/app.dart @@ -78,49 +78,59 @@ class LanternApp extends StatelessWidget { if (!snapshot.hasData) { return Container(); } + return sessionModel.language( + (context, lang, child) { + Localization.locale = lang; return GlobalLoaderOverlay( - overlayColor: Colors.black, - overlayOpacity: 0.6, - child: I18n( - initialLocale: const Locale('en', 'US'), - child: MaterialApp.router( - debugShowCheckedModeBanner: false, - theme: ThemeData( - fontFamily: _getLocaleBasedFont(currentLocal), - brightness: Brightness.light, - primarySwatch: Colors.grey, - appBarTheme: const AppBarTheme( - systemOverlayStyle: SystemUiOverlayStyle.dark, + overlayColor: Colors.black, + overlayOpacity: 0.6, + child: I18n( + initialLocale: lang == '' || lang.startsWith('en') + ? const Locale('en', 'US') + : Locale(lang), + child: MaterialApp.router( + locale: lang == '' || lang.startsWith('en') + ? const Locale('en', 'US') + : Locale(lang), + debugShowCheckedModeBanner: false, + theme: ThemeData( + fontFamily: _getLocaleBasedFont(currentLocal), + brightness: Brightness.light, + primarySwatch: Colors.grey, + appBarTheme: const AppBarTheme( + systemOverlayStyle: SystemUiOverlayStyle.dark, + ), + colorScheme: ColorScheme.fromSwatch() + .copyWith(secondary: Colors.black), + ), + title: 'app_name'.i18n, + localizationsDelegates: const [ + GlobalMaterialLocalizations.delegate, + GlobalWidgetsLocalizations.delegate, + GlobalCupertinoLocalizations.delegate, + ], + routeInformationParser: globalRouter.defaultRouteParser(), + routerDelegate: globalRouter.delegate(), + supportedLocales: const [ + Locale('ar', 'EG'), + Locale('fr', 'FR'), + Locale('en', 'US'), + Locale('fa', 'IR'), + Locale('th', 'TH'), + Locale('ms', 'MY'), + Locale('ru', 'RU'), + Locale('ur', 'IN'), + Locale('zh', 'CN'), + Locale('zh', 'HK'), + Locale('es', 'ES'), + Locale('tr', 'TR'), + Locale('vi', 'VN'), + Locale('my', 'MM'), + ], ), - colorScheme: - ColorScheme.fromSwatch().copyWith(secondary: Colors.black), ), - title: 'app_name'.i18n, - localizationsDelegates: const [ - GlobalMaterialLocalizations.delegate, - GlobalWidgetsLocalizations.delegate, - GlobalCupertinoLocalizations.delegate, - ], - routeInformationParser: globalRouter.defaultRouteParser(), - routerDelegate: globalRouter.delegate(), - supportedLocales: const [ - Locale('ar', 'EG'), - Locale('fr', 'FR'), - Locale('en', 'US'), - Locale('fa', 'IR'), - Locale('th', 'TH'), - Locale('ms', 'MY'), - Locale('ru', 'RU'), - Locale('ur', 'IN'), - Locale('zh', 'CN'), - Locale('zh', 'HK'), - Locale('es', 'ES'), - Locale('tr', 'TR'), - Locale('vi', 'VN'), - Locale('my', 'MM'), - ], - ), - ), + ); + }, ); }, ); diff --git a/lib/home.dart b/lib/home.dart index afffaceae..d8efad026 100644 --- a/lib/home.dart +++ b/lib/home.dart @@ -132,30 +132,25 @@ class _HomePageState extends State { if (isPlayVersion && version == 0) { // show privacy disclosure if it's a Play build and the terms have // not already been accepted - return PrivacyDisclosure(); + return const PrivacyDisclosure(); } - return sessionModel.language( - (BuildContext context, String lang, Widget? child) { - Localization.locale = lang; - return sessionModel.selectedTab( + return sessionModel.selectedTab( (context, selectedTab, child) => messagingModel - .getOnBoardingStatus((_, isOnboarded, child) { - final isTesting = const String.fromEnvironment( - 'driver', - defaultValue: 'false', - ).toLowerCase() == - 'true'; - return Scaffold( - body: buildBody(selectedTab, isOnboarded), - bottomNavigationBar: CustomBottomBar( - selectedTab: selectedTab, - isDevelop: developmentMode, - isTesting: isTesting, - ), - ); - }), + .getOnBoardingStatus((_, isOnboarded, child) { + final isTesting = const String.fromEnvironment( + 'driver', + defaultValue: 'false', + ).toLowerCase() == + 'true'; + return Scaffold( + body: buildBody(selectedTab, isOnboarded), + bottomNavigationBar: CustomBottomBar( + selectedTab: selectedTab, + isDevelop: developmentMode, + isTesting: isTesting, + ), ); - }, + }), ); }, ); @@ -178,7 +173,7 @@ class _HomePageState extends State { ? Chats() : Welcome(); case TAB_VPN: - return VPNTab(); + return const VPNTab(); case TAB_REPLICA: return ReplicaTab(); case TAB_ACCOUNT: