Skip to content

Commit

Permalink
Make changes to support localisation.
Browse files Browse the repository at this point in the history
  • Loading branch information
jigar-f committed Oct 2, 2023
1 parent 02494cd commit 16eaa2d
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 71 deletions.
10 changes: 7 additions & 3 deletions internalsdk/session_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
33 changes: 32 additions & 1 deletion internalsdk/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
8 changes: 8 additions & 0 deletions ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,6 @@ SPEC CHECKSUMS:
wakelock: d0fc7c864128eac40eba1617cb5264d9c940b46f
webview_flutter_wkwebview: 2e2d318f21a5e036e2c3f26171342e95908bd60a

PODFILE CHECKSUM: 757318b04676b684e713ddd4ea4c00406ab62433
PODFILE CHECKSUM: 0cfe0e959396ac6aad61f61d0b82005395de9d66

COCOAPODS: 1.11.3
2 changes: 0 additions & 2 deletions ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions lib/account/language.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>(
activeColor: pink4,
contentPadding: const EdgeInsetsDirectional.all(0),
Expand Down
90 changes: 50 additions & 40 deletions lib/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
],
),
),
);
},
);
},
);
Expand Down
39 changes: 17 additions & 22 deletions lib/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -132,30 +132,25 @@ class _HomePageState extends State<HomePage> {
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,
),
);
},
}),
);
},
);
Expand All @@ -178,7 +173,7 @@ class _HomePageState extends State<HomePage> {
? Chats()
: Welcome();
case TAB_VPN:
return VPNTab();
return const VPNTab();
case TAB_REPLICA:
return ReplicaTab();
case TAB_ACCOUNT:
Expand Down

0 comments on commit 16eaa2d

Please sign in to comment.