changeLang | uniapp与vue-i18n实现国际化多语言
kandi X-RAY | changeLang Summary
kandi X-RAY | changeLang Summary
uniapp与vue-i18n实现国际化多语言 最近uniapp的一个项目 需要用到国际化切换 做一个总结.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of changeLang
changeLang Key Features
changeLang Examples and Code Snippets
Community Discussions
Trending Discussions on changeLang
QUESTION
void main() async {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key key}) : super(key: key);
@override
Widget build(BuildContext context) {
return BlocProvider(
create: (context) => LanguageCubit(),
child: BlocBuilder(builder: (context, lang) {
return MaterialApp(
locale: lang,
title: 'Localizations Sample App',
localizationsDelegates: [
AppLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: [
const Locale('en', ''), // English, no country code
const Locale('es', ''), // Spanish, no country code
const Locale('tr', ''),
const Locale('it', ''),
],
home: Home(),
);
}),
);
}
}
class Home extends StatelessWidget {
const Home({Key key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Container(
color: Colors.amberAccent,
width: 200,
height: 200,
child: Column(
children: [
Text(AppLocalizations.of(context).helloWorld),
Divider(),
TextButton(
onPressed: () {
context.read().changeLangEs(context);
},
child: Text('Change')),
],
),
),
),
);
}
}
class LanguageCubit extends Cubit {
LanguageCubit() : super(null);
static final _languageEn = Locale('en', '');
static final _languageEs = Locale('es', '');
static final _languageTr = Locale('tr', '');
void changeLangEn(context) async {
emit(_languageEn);
}
void changeLangEs(context) async {
emit(_languageEs);
}
void changeLangTr(context) async {
emit(_languageTr);
}
}
...ANSWER
Answered 2021-May-19 at 16:52void main() async {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key key}) : super(key: key);
@override
Widget build(BuildContext context) {
return BlocProvider(
create: (context) => LanguageCubit(),
child: BlocBuilder(builder: (context, lang) {
return MaterialApp(
locale: lang,
title: 'Localizations Sample App',
localizationsDelegates: [
AppLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: [
const Locale('en', ''), // English, no country code
const Locale('es', ''), // Spanish, no country code
const Locale('tr', ''),
const Locale('it', ''),
],
home: Home(),
);
}),
);
}
}
class Home extends StatelessWidget {
//Here
const Home({Key key}) : super(key: key);
@override
Widget build(BuildContext context) {
context.read().changeStartLang();
return Scaffold(
body: Center(
child: Container(
color: Colors.amberAccent,
width: 200,
height: 200,
child: Column(
children: [
Text(AppLocalizations.of(context).helloWorld),
Divider(),
TextButton(
onPressed: () {
context.read().changeLang(context, 'en');
},
child: Text('English'),
),
TextButton(
onPressed: () {
context.read().changeLang(context, 'es');
},
child: Text('Espaniol'),
),
TextButton(
onPressed: () {
context.read().changeLang(context, 'tr');
},
child: Text('Turkish'),
),
],
),
),
),
);
}
}
class LanguageCubit extends Cubit {
LanguageCubit() : super(null);
void changeStartLang() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
String langCode = prefs.getString('lang');
print(langCode);
if (langCode != null) {
emit(Locale(langCode, ''));
}
}
void changeLang(context, String data) async {
emit(Locale(data, ''));
SharedPreferences prefs = await SharedPreferences.getInstance();
await prefs.setString('lang', data);
}
}
QUESTION
I am trying to bind SwipeView text but it is showing me nothing and other Buttons outside of the collectionview are binding correctly. when i am debugging the code then all values is showing in model class but it is not updating the UI controls Text inside collection view. I am sharing my code.Thanks in advance.
---view code--
...ANSWER
Answered 2021-Apr-16 at 07:40I am trying to bind SwipeView text but it is showing me nothing and other Buttons outside of the collectionview are binding correctly.
Your SwipeItem Text="{Binding BindActionButtons.BtnDelete}"
has some problem.
Please take a look the following code about SwipeItem text binding.
QUESTION
My app support 2 languages,English and Hebrew. When I change the language to English and minimize the app, the service notification text showing in Hebrew instead of English. Besides of the notification,the translation is working perfectly.
Now as I mentioned in the title,I figured out that its happening because my system language is Hebrew.
How can I overcome this issue ?
Thank you !
EDIT:
Change Language Button (Only MainActivity,From popup menu) -
...ANSWER
Answered 2021-Apr-02 at 12:52This solution will only work if you have pre-defined notifications String.
like String.format("Your order id %s has been processed!",orderId);
In you service, while binding notification meta-data, let service access current selected language. According to the language pass the format string to a separate method which returns translated Title & Message
QUESTION
I am getting this error while calling a TypeScript function in a React Project.
...ANSWER
Answered 2021-Mar-14 at 13:11You changeLang(language: string) receive language as type string. But you pass language as type eventKey. Some options you can do
Option 1: Change type of eventKey
QUESTION
I am trying to create a button that changes the app language. I created the string file for the language and I tried this code for changing the default language but with no success:
...ANSWER
Answered 2021-Mar-03 at 02:00There are several options, and libraries that are helpful, please read this thread: Change app language programmatically in Android
I've used this library in the past (Android 9) and worked perfectly: https://github.com/zeugma-solutions/locale-helper-android
QUESTION
I want to make a page in English that has a button which can change the language to German. I have read thousands of articles about this topic but I haven't got the answer. I know for sure I don't want to make it with Google Translator API or any API. I want to make it with pure JS. I just want to how do you do it? With a button that has a lot of lines that changes the element's text one by one:
function changeLang () { document.getElementById('someid').innerHTML = "some German text"; ... }
Or make it with const transLang { from = "en" to = "de" ...}
?
Please let me know if you have any idea how to start it.
ANSWER
Answered 2021-Feb-23 at 12:40For a "pure JS" solution, in other words none of the usual solutions:
- no Ajax to get the translated page text / replacement html
- no redirect to a different page which can handle layout incongruities
one option is to store the translations on each div and switch them over using .text()
. Do not code your translations into your javascript as that will quickly become impossible to maintain.
QUESTION
I want to create a web page that can switch into different languages, I found some tutorial but seems not used anymore for laravel 8
I want to convert this to Laravel 8 format
...ANSWER
Answered 2021-Jan-19 at 08:57Route::get('landingpage/home', [LanguageController::class,'index']);
QUESTION
I have 2 observables functions
...ANSWER
Answered 2020-Dec-03 at 04:04You can assign your subscribe function to a subscription variable.
You should probably unsubscribe to the previous refreshPageSub
each time since you are creating a new subscription each time the first subscription is called.
QUESTION
I'm trying to make multiple-choice language on my application. The language change when I selected it, but the selection not change. I use two languages, If I chose the first language (Indonesia) change, but if I chose the second language (English) the selection stays on the first choice (Indonesia), and the language change to English. This is my code.
...ANSWER
Answered 2020-Nov-06 at 12:21It seems you're setting the language correctly, but your alert dialog is not set dependent on your saved language. Instead of calling listItems, you need to call the language through shared preferences. Try the code below:
QUESTION
I have a function on my custom component which is basiaclly a callback to re-render (this.setState()) the component from where it was called from.
I am struggling with the correct syntax of these calls. Can you please assist?
Custom component
...ANSWER
Answered 2020-Oct-08 at 09:27Sorry was thinking you are using Typescript you have this option or just use this.props.afterChange() directly where you want.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install changeLang
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page