Compare commits
2 Commits
85b5d4dc7c
...
a984fc15b0
| Author | SHA1 | Date | |
|---|---|---|---|
| a984fc15b0 | |||
| 0d9118ab3e |
@@ -5,7 +5,7 @@
|
|||||||
"skills": "Skills",
|
"skills": "Skills",
|
||||||
"languages": "Languages",
|
"languages": "Languages",
|
||||||
"mother_tongue": "Native",
|
"mother_tongue": "Native",
|
||||||
"very_good": "Very goods",
|
"very_good": "Very good",
|
||||||
"about_me": "About me",
|
"about_me": "About me",
|
||||||
"additional_skills": "Additional Skills",
|
"additional_skills": "Additional Skills",
|
||||||
"work_experience": "Work experience",
|
"work_experience": "Work experience",
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ class _LandingPageState extends State<LandingPage> {
|
|||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) async {
|
WidgetsBinding.instance.addPostFrameCallback((_) async {
|
||||||
await ContentProvider.init();
|
await ContentProvider.init(context);
|
||||||
setState(() => loadingDone = true);
|
setState(() => loadingDone = true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,21 +1,37 @@
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:resume/constants.dart';
|
import 'package:resume/constants.dart';
|
||||||
|
|
||||||
class ContentProvider {
|
class ContentProvider {
|
||||||
ContentProvider._();
|
ContentProvider._();
|
||||||
|
|
||||||
static const String _jsonPath = 'assets/content/content.json';
|
static const String _baseJsonPath = 'assets/content/content';
|
||||||
|
|
||||||
static Future<bool> init() async {
|
static Future<bool> init(BuildContext context) async {
|
||||||
try {
|
try {
|
||||||
String file = await rootBundle.loadString(_jsonPath);
|
// Get the current locale
|
||||||
_content = json.decode(file);
|
final String currentLocale = Localizations.localeOf(context).languageCode;
|
||||||
|
|
||||||
|
// Construct the path with the locale
|
||||||
|
final String localizedPath = '${_baseJsonPath}_$currentLocale.json';
|
||||||
|
|
||||||
|
// Try to load the localized version first
|
||||||
|
try {
|
||||||
|
String file = await rootBundle.loadString(localizedPath);
|
||||||
|
_content = json.decode(file);
|
||||||
|
return true;
|
||||||
|
} catch (e) {
|
||||||
|
// If localized version fails, fall back to default English
|
||||||
|
String file = await rootBundle.loadString('${_baseJsonPath}_de.json');
|
||||||
|
_content = json.decode(file);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
print('Error loading content: $e');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static Map<String, dynamic> _content = {
|
static Map<String, dynamic> _content = {
|
||||||
|
|||||||
@@ -27,7 +27,8 @@ flutter:
|
|||||||
uses-material-design: true
|
uses-material-design: true
|
||||||
|
|
||||||
assets:
|
assets:
|
||||||
- assets/content/content.json
|
- assets/content/content_de.json
|
||||||
|
- assets/content/content_en.json
|
||||||
- assets/profile.jpg
|
- assets/profile.jpg
|
||||||
- assets/de_icon.png
|
- assets/de_icon.png
|
||||||
- assets/gb_icon.png
|
- assets/gb_icon.png
|
||||||
|
|||||||
Reference in New Issue
Block a user