i18next deep key value react native - reactjs

{
"content": {
"en": {
"transfer_screen_amount_title": "Amount",
"demo_screen_welcome_title": "Welcome"
},
"bm": {
"transfer_screen_amount_title": "Jumlah",
"demo_screen_welcome_title": "Selamat Datang"
}
}
}
I reckon that in order to retrieve the value, we can set it like this t('content.en.transfer_screen_amount_title').
what if i want to use it like this instead t('transfer_screen_amount_title') ??

It depends on how your translations are loaded: https://www.i18next.com/how-to/add-or-load-translations
Here an example loading the resources on init:
https://github.com/i18next/react-i18next/blob/master/example/react-native/App.js#L20
So your code would look like this:
i18next
.use(languageDetector)
.use(initReactI18next)
.init({
fallbackLng: 'en',
debug: true,
defaultNS: 'content',
resources: {
en: {
content: {
transfer_screen_amount_title: 'Amount',
demo_screen_welcome_title: 'Welcome',
},
},
bm: {
content: {
transfer_screen_amount_title: 'Jumlah',
demo_screen_welcome_title: 'Selamat Datang',
},
},
},
});
// t('transfer_screen_amount_title')
Maybe read also: https://www.i18next.com/principles/namespaces

Related

How to ignore some routes with getStaticPath?

I am using multilanguage with getStaticPath generation (English and Spanish) but i am getting some errors cause of default language.
I am trying to generate these routes:
[
{ params: { slug: 'ruta-en-espaniol', locale: 'es' } },
{ params: { slug: 'path-in-english', locale: 'en' } },
]
But Next.js is generating not 2 routes...even 3.
/en/ruta-en-espaniol
/es/ruta-en-espaniol
/en/path-in-english
is there some property to disable this? Maybe something like this?:
{ params: { slug: 'ruta-en-espaniol', locale: 'en', ignoreRoute: true } }

Alexa smart home capabilities overriding one another

I have an Alexa project for smart home shades that include two range controllers, a brightness controller, and a toggle controller on each endpoint.
The two range controllers, toggle controller, and brightness controller all have different instances and friendlyNames.
When issuing commands to Alexa, anything containing a percentage is defaulting to the brightness controller regardless of how the command is phrased. If I fully remove the brightness controller and attempt to issue a rotation command (range controller), depending on the device, I get incredibly inconsistent results stating it doesn't know how to set the setting. Some devices will work around 90% at first and will then suddenly fail consistently. Other devices wont work at all. No device is consistently working.
If I reduce down to any one of the capabilities, it works nearly 100% of the time.
Has anyone else experienced this behavior and is there any solution?
Capability code:
export const ROTATE_CAPABILITY = {
type: "AlexaInterface",
interface: "Alexa.RangeController",
version: "3",
instance: "Blind.Rotate",
properties: {
supported: [{ name: "rangeValue" }],
proactivelyReported: false,
retrievable: true,
},
capabilityResources: {
friendlyNames: [
{
"#type": "text",
value: {
text: "Vane",
locale: "en-US"
}
},
{
"#type": "text",
value: {
text: "Tilt",
locale: "en-US"
}
},
{
"#type": "text",
value: {
text: "Angle",
locale: "en-US"
}
}
]
},
configuration: {
supportedRange: {
minimumValue: 0,
maximumValue: 100,
precision: 1,
},
unitOfMeasure: "Alexa.Unit.Percent"
}
}
export const BRIGHTNESS_CAPABILITY = {
type: "AlexaInterface",
interface: "Alexa.BrightnessController",
version: "3",
instance: "Blind.Brightness",
properties: {
supported: [
{
name: "brightness"
}
],
proactivelyReported: false,
retrievable: true
}
}
export const BRIGHTNESS_TOGGLE = {
type: "AlexaInterface",
interface: "Alexa.ToggleController",
instance: "Blind.Light",
version: "3",
properties: {
supported: [
{
name: "toggleState"
}
],
proactivelyReported: false,
retrievable: true,
nonControllable: false
},
capabilityResources: {
friendlyNames: [
{
"#type": "text",
value: {
text: "Shade Light",
locale: "en-US"
}
},
{
"#type": "text",
value: {
text: "Light",
locale: "en-US"
}
}
]
}
}
export const MAIN_CAPABILITY = {
type: "AlexaInterface",
interface: "Alexa.RangeController",
instance: "Blind.Lift",
version: "3",
properties: {
supported: [{
name: "rangeValue",
},],
proactivelyReported: false,
retrievable: true,
},
capabilityResources: {
friendlyNames: [
{
"#type": "text",
value: {
text: "Shade",
locale: "en-US"
}
}
],
},
configuration: {
supportedRange: {
minimumValue: 0,
maximumValue: 100,
precision: 1,
},
unitOfMeasure: "Alexa.Unit.Percent",
},
semantics: {
actionMappings: [{
"#type": "ActionsToDirective",
actions: ["Alexa.Actions.Close"],
directive: {
name: "SetRangeValue",
payload: {
rangeValue: 0,
},
},
},
{
"#type": "ActionsToDirective",
actions: ["Alexa.Actions.Open"],
directive: {
name: "SetRangeValue",
payload: {
rangeValue: 100,
},
},
},
{
"#type": "ActionsToDirective",
actions: ["Alexa.Actions.Lower"],
directive: {
name: "AdjustRangeValue",
payload: {
rangeValueDelta: -10,
rangeValueDeltaDefault: false,
},
},
},
{
"#type": "ActionsToDirective",
actions: ["Alexa.Actions.Raise"],
directive: {
name: "AdjustRangeValue",
payload: {
rangeValueDelta: 10,
rangeValueDeltaDefault: false,
},
},
},
],
stateMappings: [{
"#type": "StatesToValue",
states: ["Alexa.States.Closed"],
value: 0,
},
{
"#type": "StatesToRange",
states: ["Alexa.States.Open"],
range: {
minimumValue: 1,
maximumValue: 100,
},
},
],
},
}

Create a custom element in EditorJs

I added EditorJs plugin in my react js application:
import ReactDOM from "react-dom";
import React, { Component } from "react";
import EditorJs from "react-editor-js";
import { EDITOR_JS_TOOLS } from "./constants";
class ReactEditor extends Component {
render() {
return (
<EditorJs
tools={EDITOR_JS_TOOLS}
data={{
blocks: [
{
type: "header",
data: {
text: "Editor.js",
level: 2
}
},
{
type: "paragraph",
data: {
}
},
{
type: "header",
data: {
text: "Key features",
level: 3
}
},
{
type: "list",
data: {
style: "unordered",
items: [
"It is a block-styled editor",
"It returns clean data output in JSON",
"Designed to be extendable and pluggable with a simple API"
]
}
},
{
type: "header",
data: {
text: "What does it mean Β«block-styled editorΒ»",
level: 3
}
},
{
type: "paragraph",
data: {
text:
'Workspace in classic editors is made of a single contenteditable element, used to create different HTML markups. Editor.js <mark class="cdx-marker">workspace consists of separate Blocks: paragraphs, headings, images, lists, quotes, etc</mark>. Each of them is an independent contenteditable element (or more complex structure) provided by Plugin and united by Editor\'s Core.'
}
},
{
type: "paragraph",
data: {
text:
'There are dozens of ready-to-use Blocks and the simple API for creation any Block you need. For example, you can implement Blocks for Tweets, Instagram posts, surveys and polls, CTA-buttons and even games.'
}
},
{
type: "header",
data: {
text: "What does it mean clean data output",
level: 3
}
},
{
type: "paragraph",
data: {
text:
"Classic WYSIWYG-editors produce raw HTML-markup with both content data and content appearance. On the contrary, Editor.js outputs JSON object with data of each Block. You can see an example below"
}
},
{
type: "paragraph",
data: {
text:
'Given data can be used as you want: render with HTML for <code class="inline-code">Web clients</code>, render natively for <code class="inline-code">mobile apps</code>, create markup for <code class="inline-code">Facebook Instant Articles</code> or <code class="inline-code">Google AMP</code>, generate an <code class="inline-code">audio version</code> and so on.'
}
},
{
type: "paragraph",
data: {
text:
"Clean data is useful to sanitize, validate and process on the backend."
}
},
{
type: "delimiter",
data: {}
},
{
type: "paragraph",
data: {
text:
"We have been working on this project more than three years. Several large media projects help us to test and debug the Editor, to make it's core more stable. At the same time we significantly improved the API. Now, it can be used to create any plugin for any task. Hope you enjoy. 😏"
}
},
{
type: "image",
data: {
file: {
url:
"https://codex.so/upload/redactor_images/o_e48549d1855c7fc1807308dd14990126.jpg"
},
caption: "",
withBorder: true,
stretched: false,
withBackground: false
}
}
],
version: "2.12.4"
}}
/>
);
}
}
ReactDOM.render(<ReactEditor />, document.getElementById("root"));
According to the documentation i can create a custom element:
render() {
return (
<EditorJs holder="custom">
<div id="custom" />
</EditorJs>
);
}
Question: I want to add as a custom element an input: <input type="text"/>, but i don't manage even if i do:
<EditorJs holder="custom">
<input id="custom" type="text"/>
</EditorJs>
Who knows how to add this custom element in the plugin above?
demo: https://codesandbox.io/embed/react-editor-js-23opz
I found in the documentation that i can create a plugin for editor.js:
https://editorjs.io/the-first-plugin. One of example looks like this:
class SimpleImage {
static get toolbox() {
return {
title: 'Image',
icon: '<svg width="17" height="15" viewBox="0 0 336 276" xmlns="http://www.w3.org/2000/svg"><path d="M291 150V79c0-19-15-34-34-34H79c-19 0-34 15-34 34v42l67-44 81 72 56-29 42 30zm0 52l-43-30-56 30-81-67-66 39v23c0 19 15 34 34 34h178c17 0 31-13 34-29zM79 0h178c44 0 79 35 79 79v118c0 44-35 79-79 79H79c-44 0-79-35-79-79V79C0 35 35 0 79 0z"/></svg>'
};
}
render() {
return document.createElement('input');
}
save(blockContent) {
return {
url: blockContent.value
}
}
}

flowplayer playlist track auto change is giving error

I am using Flowplayer(in Mean js audio streaming project) for RTMP audio streaming with Wowza streaming engine software and using below service of angular js.
app.service('flowPlayerService', ['$cookies','constant',function ($cookies,constant) {
player: null,
currentTitle:'',
constructPlaylist: function (playlist) {
var currentObj = this;
this.player = flowplayer("flashPlayer", "lib/flowplayer/flowplayer-3.2.18.swf", {
playlist:playlist,
onBegin: function(talk){
console.log('clip changed');
},
onFail:function(){
//alert('loading failed');
},
onFinish:function(){
console.log('finisheds');
},
// engine:'html5',
// Specify the location of the RTMP plugin.
plugins: {
rtmp: {
url: 'lib/flowplayer/flowplayer.rtmp-3.2.13.swf',
netConnectionUrl: 'rtmp://10.10.3.11/vod'
},
controls: {
autoHide: 'never',
url: 'lib/flowplayer/flowplayer.controls-3.2.16.swf',
tooltips: {
buttons: true,
fullscreen: false,
pause: 'Continue playing',
},
playlist: true,
fullscreen:false,
},
dock: {
enabled:false,
gap: 5,
autoHide: false
}
},
onMouseOut:function(){
console.log('mouse out');
}
//canvas: {backgroundGradient: 'none'}
});
console.log(this.player);
//this.player = flowplayer();
},
}
While playing single track it is working fine.But when I try to run playlist first track plays file but when first track finished it gives error like:-
VM36229:1 [ERROR] time 13:51:35.968 :: 201, Unable to load stream or clip file, cannot play video: Error #2154, clip: '[Clip] 'mp3:02 Jashn-E-Bahaara-1469775940586.mp3''
below playlist array example:-
[{
url:"mp3:track.mp3",
provider:"rtmp",
title:'track title'
},
{
url:"mp3:track1.mp3",
provider:"rtmp",
title:'track title1'
}
]
please help.
Passing the "duration" to clip objects resolve this issue.

i18next using Backbone and requireJs not work

im having troubles using i18next with requireJs and Backbone. I have a folder named 'i18n' where all my resources are listed.
content of i18 folder:
resources-locale_en.js
resources-locale_es.js
resources-locale_fr.js
resources-locale_it.js
content of resources-locale_es.js
{
"john doe": "John Doe",
"my profile": "mi perfil",
"settings": "Ajustes",
"my tasks": "mis tareas",
"red": "rojo",
"orange": "orange"
}
On my require config.js:
.
.
.
//shim
i18n: {
deps: ['jquery']
}
.
.
.
var i18n = require('i18n');
i18n.init({
getAsync: false,
lang: 'en',
debug: true,
fallbackLng: false,
load:'unspecific',
resGetPath: "__ns_____lng__.js",
ns: {
namespaces: ['i18n/resources-locale'],
defaultNs: 'i18n/resources-locale'
}
}).done(function() {
new AppRouter({});
Backbone.history.start({
pushState: true
});
})
When DOM is loaded i run:
$("[data-i18n]").i18n();
but just list elements that content data-i18n, not transform anything
[ <span data-i18n=​"My Profile">​</span>​
, <span data-i18n=​"My Tasks">​</span>​
, <span data-i18n=​"Lock">​</span>​
, <span data-i18n=​"Log Out">​</span>​
, <span data-i18n=​"User Profile">​</span>​
, <span data-i18n=​"Dashboard">​</span
]
What im doing wrong?

Resources