Skip to content

Commit 6e969f6

Browse files
authored
feat: add Hindi language support (#3252)
1 parent 9024d74 commit 6e969f6

94 files changed

Lines changed: 943 additions & 140 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

lib/communication/sensors/apds9960.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import '../../l10n/app_localizations.dart';
77
import '../../providers/locator.dart';
88

99
class APDS9960 {
10-
AppLocalizations appLocalizations = getIt.get<AppLocalizations>();
10+
AppLocalizations get appLocalizations => getIt.get<AppLocalizations>();
1111

1212
static const String tag = "APDS9960";
1313

lib/communication/sensors/bmp180.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import '../../l10n/app_localizations.dart';
77
import '../../providers/locator.dart';
88

99
class BMP180 {
10-
AppLocalizations appLocalizations = getIt.get<AppLocalizations>();
10+
AppLocalizations get appLocalizations => getIt.get<AppLocalizations>();
1111

1212
static const String tag = "BMP180";
1313

lib/constants.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const oscilloscopeScreenTitleKey = 'oscilloscope_screen_title';
1212

1313
const int kMaxFileNameLength = 200;
1414

15-
AppLocalizations appLocalizations = getIt.get<AppLocalizations>();
15+
AppLocalizations get appLocalizations => getIt.get<AppLocalizations>();
1616

1717
List<String> instrumentIcons = [
1818
'assets/icons/tile_icon_oscilloscope.png',

lib/l10n/app_en.arb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,16 @@
170170
"waveGeneratorConfigs": "Wave Generator Configurations",
171171
"analyze": "Analyze",
172172
"settings": "Settings",
173+
"language": "Language",
174+
"english": "English",
175+
"hindi": "Hindi",
176+
"frontLayout": "Front Layout",
177+
"backLayout": "Back Layout",
178+
"pinLayout": "Pin Layout",
179+
"licensesIntro": "This app uses the following open source packages. Their original licenses (in English, as legally required) are shown below.",
180+
"licenseDescription": "Description",
181+
"licenseHomepage": "Homepage",
182+
"licenseText": "License",
173183
"autoStart": "Auto Start",
174184
"autoStartText": "Auto start app when PSLab device is connected",
175185
"export": "Export Data Format",

lib/l10n/app_hi.arb

Lines changed: 680 additions & 1 deletion
Large diffs are not rendered by default.

lib/main.dart

Lines changed: 69 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ void main() {
5151
);
5252
}
5353

54+
bool _boardInitialized = false;
55+
5456
class MyApp extends StatelessWidget {
5557
const MyApp({super.key});
5658

@@ -65,9 +67,13 @@ class MyApp extends StatelessWidget {
6567
builder: (context, provider, child) {
6668
return MaterialApp(
6769
debugShowCheckedModeBanner: false,
70+
locale: Locale(provider.config.languageCode),
6871
builder: (context, child) {
6972
registerAppLocalizations(AppLocalizations.of(context)!);
70-
getIt<BoardStateProvider>().initialize();
73+
if (!_boardInitialized) {
74+
_boardInitialized = true;
75+
getIt<BoardStateProvider>().initialize();
76+
}
7177
appLocalizations = getIt.get<AppLocalizations>();
7278
return child!;
7379
},
@@ -79,31 +85,53 @@ class MyApp extends StatelessWidget {
7985
supportedLocales: AppLocalizations.supportedLocales,
8086
initialRoute: '/',
8187
routes: {
82-
'/': (context) => const InstrumentsScreen(),
83-
'/oscilloscope': (context) => const OscilloscopeScreen(),
84-
'/multimeter': (context) => const MultimeterScreen(),
85-
'/waveGenerator': (context) => const WaveGeneratorScreen(),
86-
'/logicAnalyzer': (context) => const LogicAnalyzerScreen(),
87-
'/powerSource': (context) => const PowerSourceScreen(),
88-
'/compass': (context) => const CompassScreen(),
89-
'/connectDevice': (context) => const ConnectDeviceScreen(),
90-
'/faq': (context) => FAQScreen(),
91-
'/settings': (context) => const SettingsScreen(),
92-
'/aboutUs': (context) => const AboutUsScreen(),
93-
'/softwareLicenses': (context) => SoftwareLicensesScreen(),
94-
'/accelerometer': (context) => const AccelerometerScreen(),
95-
'/gyroscope': (context) => const GyroscopeScreen(),
96-
'/roboticArm': (context) => const RoboticArmScreen(),
97-
'/luxmeter': (context) => const LuxMeterScreen(),
98-
'/barometer': (context) => const BarometerScreen(),
99-
'/soundmeter': (context) => const SoundMeterScreen(),
100-
'/thermometer': (context) => const ThermometerScreen(),
101-
'/sensors': (context) => const SensorsScreen(),
102-
'/experiments': (context) => const ExperimentsScreen(),
103-
'/loggedData': (context) => LoggedDataScreen(
104-
instrumentNames: instrumentNames,
105-
appBarName: appLocalizations!.loggedData,
106-
instrumentIcons: instrumentIcons,
88+
'/': (context) =>
89+
const _LocaleAware(child: InstrumentsScreen()),
90+
'/oscilloscope': (context) =>
91+
const _LocaleAware(child: OscilloscopeScreen()),
92+
'/multimeter': (context) =>
93+
const _LocaleAware(child: MultimeterScreen()),
94+
'/waveGenerator': (context) =>
95+
const _LocaleAware(child: WaveGeneratorScreen()),
96+
'/logicAnalyzer': (context) =>
97+
const _LocaleAware(child: LogicAnalyzerScreen()),
98+
'/powerSource': (context) =>
99+
const _LocaleAware(child: PowerSourceScreen()),
100+
'/compass': (context) =>
101+
const _LocaleAware(child: CompassScreen()),
102+
'/connectDevice': (context) =>
103+
const _LocaleAware(child: ConnectDeviceScreen()),
104+
'/faq': (context) => _LocaleAware(child: FAQScreen()),
105+
'/settings': (context) =>
106+
const _LocaleAware(child: SettingsScreen()),
107+
'/aboutUs': (context) =>
108+
const _LocaleAware(child: AboutUsScreen()),
109+
'/softwareLicenses': (context) =>
110+
_LocaleAware(child: SoftwareLicensesScreen()),
111+
'/accelerometer': (context) =>
112+
const _LocaleAware(child: AccelerometerScreen()),
113+
'/gyroscope': (context) =>
114+
const _LocaleAware(child: GyroscopeScreen()),
115+
'/roboticArm': (context) =>
116+
const _LocaleAware(child: RoboticArmScreen()),
117+
'/luxmeter': (context) =>
118+
const _LocaleAware(child: LuxMeterScreen()),
119+
'/barometer': (context) =>
120+
const _LocaleAware(child: BarometerScreen()),
121+
'/soundmeter': (context) =>
122+
const _LocaleAware(child: SoundMeterScreen()),
123+
'/thermometer': (context) =>
124+
const _LocaleAware(child: ThermometerScreen()),
125+
'/sensors': (context) =>
126+
const _LocaleAware(child: SensorsScreen()),
127+
'/experiments': (context) =>
128+
const _LocaleAware(child: ExperimentsScreen()),
129+
'/loggedData': (context) => _LocaleAware(
130+
child: LoggedDataScreen(
131+
instrumentNames: instrumentNames,
132+
appBarName: appLocalizations!.loggedData,
133+
instrumentIcons: instrumentIcons,
134+
),
107135
),
108136
},
109137
);
@@ -114,6 +142,21 @@ class MyApp extends StatelessWidget {
114142
}
115143
}
116144

145+
class _LocaleAware extends StatelessWidget {
146+
final Widget child;
147+
const _LocaleAware({required this.child});
148+
149+
@override
150+
Widget build(BuildContext context) {
151+
return Consumer<SettingsConfigProvider>(
152+
builder: (_, provider, __) => KeyedSubtree(
153+
key: ValueKey(provider.config.languageCode),
154+
child: child,
155+
),
156+
);
157+
}
158+
}
159+
117160
void _preCacheImages(BuildContext context) {
118161
for (final path in instrumentIcons) {
119162
precacheImage(AssetImage(path), context);

lib/models/settings_config.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,39 @@
11
class SettingsConfig {
22
final bool autoStart;
33
final String exportFormat;
4+
final String languageCode;
45

56
const SettingsConfig({
67
this.autoStart = true,
78
this.exportFormat = 'CSV',
9+
this.languageCode = 'en',
810
});
911

1012
SettingsConfig copyWith({
1113
bool? autoStart,
1214
String? exportFormat,
15+
String? languageCode,
1316
}) {
1417
return SettingsConfig(
1518
autoStart: autoStart ?? this.autoStart,
1619
exportFormat: exportFormat ?? this.exportFormat,
20+
languageCode: languageCode ?? this.languageCode,
1721
);
1822
}
1923

2024
Map<String, dynamic> toJson() {
2125
return {
2226
'autoStart': autoStart,
2327
'exportFormat': exportFormat,
28+
'languageCode': languageCode,
2429
};
2530
}
2631

2732
factory SettingsConfig.fromJson(Map<String, dynamic> json) {
2833
return SettingsConfig(
2934
autoStart: json['autoStart'] ?? true,
3035
exportFormat: json['exportFormat'] ?? 'CSV',
36+
languageCode: json['languageCode'] ?? 'en',
3137
);
3238
}
3339
}

lib/others/barometer_pressure_experiment.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import '../models/experiment_step.dart';
44
import '../models/experiment_config.dart';
55
import '../providers/locator.dart';
66

7-
AppLocalizations appLocalizations = getIt.get();
7+
AppLocalizations get appLocalizations => getIt.get<AppLocalizations>();
88

99
class StabilizePressureReadingStep extends ExperimentStep {
1010
StabilizePressureReadingStep()

lib/others/csv_service.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import '../l10n/app_localizations.dart';
1111
import '../providers/locator.dart';
1212

1313
class CsvService {
14-
AppLocalizations appLocalizations = getIt.get<AppLocalizations>();
14+
AppLocalizations get appLocalizations => getIt.get<AppLocalizations>();
1515

1616
Future<Directory> getInstrumentDirectory(String instrumentName) async {
1717
if (Platform.isAndroid) {

lib/others/light_distance_experiment.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import '../models/experiment_step.dart';
44
import '../models/experiment_config.dart';
55
import '../providers/locator.dart';
66

7-
AppLocalizations appLocalizations = getIt.get<AppLocalizations>();
7+
AppLocalizations get appLocalizations => getIt.get<AppLocalizations>();
88

99
class MoveTowardsLightStep extends ExperimentStep {
1010
MoveTowardsLightStep()

0 commit comments

Comments
 (0)