Flutter get language strings within a widget without changing context locale - flutter

I have been able to implement multiple language support in Flutter using the developer docs (https://flutter.dev/docs/development/accessibility-and-localization/internationalization)
I was wondering if there is a way to access the language strings we define within a widget but by not changing the locale of the context.
Here is my use case.
I am presenting a set of books as a grid of cards. The content is of different languages (e.g. English and Spanish). Now, based on the language I would like to use some of the text strings from the locale just for one card of the grid.
For example, if the data of each book is: language (en, es), title (...), no_pages (x). Then, when presenting the grid I would like to use the word "pages" from the string either as "Pages" or "Pagina".
How does one go about it? Thanks

Take a look at the language_builder package in pub.dev It is very easy to use. By wrapping your root widget with LanguageBuilder you can configure your app's language. Tell your app to use the phones' language or change it manually from the app.
void main() {
runApp(
MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Language Builder Example',
home: LanguageBuilder(
useDeviceLanguage: false,
defaultLanguage: 'en',
languagesMap: Languages.languages,
child: MainPage(),
//splash: Container(),
),
),
);
}
class Languages {
static Map<String, String> languages = {
"tr": """{
"main_page": {
"title": "Ana Sayfa",
"second_page": "İkinci Sayfa"
},
"second_page": {
"title": "İkinci Sayfa",
"main_page": "Ana Sayfa",
"message":"Bu sayfa 2. sayfadır."
}
}""",
"en": """{
"main_page": {
"title": "Main Page",
"second_page": "Second Page"
},
"second_page": {
"title": "Second Page",
"main_page": "Main Page",
"message":"This is 2nd page."
}
}""",
"de": """{
"main_page": {
"title": "Hauptseite",
"second_page": "Zweite Seite"
},
"second_page": {
"title": "Zweite Seite",
"main_page": "Hauptseite",
"message":"Dies ist die 2. Seite."
}
}"""
};
}
//MainPage
Scaffold(
appBar: AppBar(
title: Text(
LanguageBuilder.texts['main_page']['title'],
),
),
),
You can configure the example above for your case. For more info take a look at language_builder:
language_builder

Related

Add inline styles to links (something like link_class_list)

is there some way to add something like link_class_list, but make it use inline styles instead of classes?
I need to make it use styles, because some email clients block the <style> tag and we need to support most of the clients.
Werer loading the editor using JQuery. TinyMCE is on version 5.
Current config:
plugins: ["link, image"],
link_class_list: [
{ title: "None", value: "" },
{ title: "External Link", value: "ext_link" },
{
title: "Internal Links",
menu: [
{ title: "Internal Support Link", value: "int_sup_link" },
{ title: "Internal Marketing Link", value: "int_mark_link" },
{ title: "Other Internal Link", value: "int_other_link" },
],
},
]
Current output (with class):
<a data-mce-href="seznam.cz" href="seznam.cz" class="int_mark_link" data-mce-selected="inline-boundary">
Link example
</a>
Expected output (with style):
<a data-mce-href="seznam.cz" href="seznam.cz" style="color: red;" data-mce-selected="inline-boundary">
Link example
</a>

Issue in make a phone call within Google Assistant App

I try to implement button in basic card i got an error
API Version 2: Failed to parse JSON response string with 'INVALID_ARGUMENT' error: "(expected_inputs[0].input_prompt.rich_initial_prompt.items[1].basic_card.buttons[0].open_url_action) versions: Cannot find field." HTTP Status Code: 200.
conv.ask(new BasicCard({
text: `This is a basic card. Text in a basic card can include "quotes" and`,
subtitle: 'This is a subtitle',
buttons: [
{
"title": "Call",
"openUrlAction": {
"url": "tel:+91123456789",
"androidApp": {
"packageName": "com.android.phone"
},
"versions": []
}
},
],
"formattedText": "Some text",
image: new Image({
url: 'https://storage.googleapis.com/actionsresources/logo_assistant_2x_64dp.png',
alt: 'Image alternate text',
}),
"title": "Card Title"
}));
and I tried all the ways add another empty object in button array also same error:
buttons: [
{
"title": "Call",
"openUrlAction": {
"url": "tel:+91123456789",
"androidApp": {
"packageName": "com.android.phone"
},
"versions": []
}
},
{}
],
Tried code below got error:
expected_inputs[0].input_prompt.rich_initial_prompt.items[1].basic_card.buttons[0].open_url_action: the protocol must be http or https.
buttons: new Button({
"title": "button text",
'url': "tel:+91123456789",
"androidApp": {
"packageName": "com.android.phone"
}
})
got response in action console simulator:
"buttons": [
{
"title": "button text",
"openUrlAction": {
"url": "tel:+919177723773"
}
}
]
You cannot open a tel: URL through the Assistant.
As the error noted:
expected_inputs[0].input_prompt.rich_initial_prompt.items[1].basic_card.buttons[0].open_url_action: the protocol must be http or https.
Keep in mind that the Assistant runs on devices that do not support tel: URLs, even if they support https: URLs.
The URL property that you are using includes a phonenumber. The link property can only use links to a webpage. This also comes back in the error message that you are getting:
"the protocol must be http or https.".
So if you want to fix the error, you need to include a http or https link in your button instead of a phonenumber.
As for calling a phonenumber from the Google Assistant App, I'm not sure if this feature is supported at the moment.

Change icon in Header Navigation menu - SAPUI5

I need to change icon in the header Navigation Menu. I would like to customize the icon for "Master Data Display".
The items in the navigation menu, including the icons can be managed with the ShellUIService.
To change the icon you must call setHierarchy( aHierarchyLevels ) with the list of items that should be shown in the menu.
aHierarchyLevels is structured as follows:
[
{
title: "Main View",
icon: "sap-icon://documents",
intent: "#Action-sameApp"
},
{
title: "View 2",
subtitle: "Application view number 2",
intent: "#Action-sameApp&/View2/"
},
{
title: "View 3",
subtitle: "Application view number 3",
intent: "#Action-sameApp&/View3/"
}
]

askWithList on Actions on Google

I'm following the sample code for Action on Google responses at the following link:
https://developers.google.com/actions/assistant/responses
I want the list response to appear when the user initiates the text intent, but all I get is "Your App isn’t responding right now. Try again soon." Here is the code that I'm using (it's copy and paste for the most part from the link):
function textIntent(app) {
app.askWithList(app.buildRichResponse()
.addSimpleResponse('Alright')
.addSuggestions(
['Basic Card', 'List', 'Carousel', 'Suggestions']),
// Build a list
app.buildList('Things to learn about')
// Add the first item to the list
.addItems(app.buildOptionItem('MATH_AND_PRIME',
['math', 'math and prime', 'prime numbers', 'prime'])
.setTitle('Math & prime numbers')
.setDescription('42 is an abundant number because the sum of its ' +
'proper divisors 54 is greater…')
)
// Add the second item to the list
.addItems(app.buildOptionItem('EGYPT',
['religion', 'egypt', 'ancient egyptian'])
.setTitle('Ancient Egyptian religion')
.setDescription('42 gods who ruled on the fate of the dead in the ' +
'afterworld. Throughout the under…')
)
// Add third item to the list
.addItems(app.buildOptionItem('RECIPES',
['recipes', 'recipe', '42 recipes'])
.setTitle('42 recipes with 42 ingredients')
.setDescription('Here\'s a beautifully simple recipe that\'s full ' +
'of flavor! All you need is some ginger and…')
)
);
}
let actionMap = new Map();
actionMap.set(app.StandardIntents.MAIN, mainIntent);
actionMap.set(app.StandardIntents.TEXT, textIntent);
app.handleRequest(actionMap);
Here is my action.json:
{
"actions": [
{
"description": "Default Welcome Intent",
"name": "MAIN",
"fulfillment": {
"conversationName": "welcome"
},
"intent": {
"name": "actions.intent.MAIN"
}
},
],
"conversations": {
"welcome": {
"name": "welcome",
"url": "https://example.com"
},
}
}
Any help would be much appreciated! Thank you in advance.
You're using Actions version 2 features, but the actions.json package isn't specifying a version, so it defaults to version 1.
The "conversations" section of actions.json should look something like:
"conversations": {
"welcome": {
"name": "welcome",
"url": "https://example.com",
"fulfillmentApiVersion": 2
},
}

Display Language list in mutifield

I want to display list of languages in dialog "multi field"
I have already tried with
CQ.utils.WCM.getLanguageOptions
CQ.utils.WCM.getLanguageOptions would solve the puprose. Use it as the optionsProvider for the selection widget.
{
"jcr:primaryType": "cq:Widget",
"name": "./demo",
"xtype": "multifield",
"fieldLabel": "Choose Applicable Languages",
"fieldConfig": {
"jcr:primaryType": "nt:unstructured",
"optionsProvider": "CQ.utils.WCM.getLanguageOptions",
"type": "select",
"xtype": "selection"
}
}
For more information, check the CQ.WCM API