i try'd to use \n but its not working. any ideas?
{
name: "learn-teambuilding",
title: "What Do We Know about Software Development in
Startups?",
content: [
'• use of easy-to-implement tools to facilitate product development Nevertheless, the absence of structure might hinder important activities.\ntest'
]
},
It's ok and already works for me ! you can also use back tick (this symbol: ``) and put your string in it
Related
I am trying to dynamically render a form based on a series of questions which are provided from an API. The form should render the questions individually (one by one) and should not add the next question if it has already been triggered.
I have managed to do the above, quite easily but then when it comes to the logic surrounding a "multiple choice" I am starting to have great difficulty, whereby I am currently unable to determine the logic which could help the above scenario.
The API returns a resource such as the following to render a form:
[
{
id: 1,
title: 'What is your name?',
type: 'free-text'
},
{
id: 2,
title: 'What is your age?',
type: 'number'
},
{
id: 3,
title: 'What is your occupations?',
type: 'choice',
allowMultiple: true,
choices: [
{ value: 'Developer', goTo: 1 },
{ value: 'Engineer' }
]
},
{
id: 4,
title: 'Any comments?',
type: 'free-text'
}
]
From the above example, goTo simulates what question that answer should go to. In this above example, after the use select "Developer" they will be greeted with "What is your name?" question again.
I have currently tried the following (React):
When the form is rendered it renders in the following format {questionId}-{index}. This is due to the same question being able to render on the screen at a given time, therefore "questionId" wouldn't be sufficient and would cause duplications.
Please find the link to codesandbox here:
https://codesandbox.io/s/unruffled-flower-pwyfbd
You will see that it works correctly for inputs, but then when using the choice the logic is messed up.
What should happen is the following:
When "What is your name?" has a value -> load "What is your age?"
When "What is your age" has a value -> load "What is your
occupations?"
When "Developer" option is checked -> load "What is your name" (due to the branching).
Loop to the start.
When "Engineer" option is checked -> load "Any comments?"
If "Developer" is unchecked, it removed all inputs / checkboxes that were generated from that checkbox.
If "Engineer" option is unchecked, it removes all inputs / checkboxes that were generated from that checkbox.
** please note, I could be going in the completely wrong direction with this and I am happy for suggestions on how to improve the code / a alternative method to go down **
I'm trying to refactor my React frontend code, basically all the hardcoded strings are to come from CMS and for that I have made a custom hook that fetches the string my components need.
I have a constant file which previously used to refer this string file that contained all the hardcoded strings before, now since I have the hook, how do I use it to replace this string file inside my constants file?
export const SCORES_INFORMATION_BY_SEVERITY_LEVEL: Record<string, IScoreInformation> = {
[DepressionLevels.MinimalDepression]: {
score: '0 - 4',
title: 'No or minimal depression',
description: Strings.minimalDepressionDescription,
},
[DepressionLevels.MildDepression]: {
score: '5 - 9',
title: 'Mild depression',
description: Strings.mildDepressionDescription,
},
[DepressionLevels.ModerateDepression]: {
score: '10 - 14',
title: 'Moderate depression',
description: Strings.moderateDepressionDescription,
}
};
The description key here is what getting referenced from the String file as you can see.
What I thought could be a possible solution:
I decouple this part of the file and put it in the component itself that refers it as obviously I can't use hook in the consts file. The problem with that is that this constant is getting used at multiple places and I will end up repeating my code
Just make few another constants for these strings in the constant file itself and leave it be but I'm not sure if it's the right thing to do.
I currently have the translated English and Japanese .json file in the format:
{
"en": [{
"id": "Cancel",
"defaultMessage": "Cancel"
}, {
"id": "CommonTags",
"defaultMessage": "Common Tags"
}]
"ja": [{
"id": "Cancel",
"defaultMessage": "キャンセル"
}, {
"id": "CommonTags",
"defaultMessage": "共通タグ"
}]}
My question is, why do I need to define the messages now considering that I already have all of these generated and translated? I am simply like to access them in the following way but getting an error:
var messages_ja = require("../../../Resources/Resources.ja2.js.json");
class LocalizedApp extends React.Component {
props: any;
static propTypes: { intl: (object: any, key: string, componentName: string, ...rest: any[]) => Error | null; };
render() {
return (...
<h1>{this.props.intl.formatMessage({ id: messages_ja.Cancel })}</h1>);}}
I get the following error:
[React Intl] An id must be provided to format a message.
Repeating my question:
Do I really need to incorporate the ecosystem for defining messages.
If so, why?
Is it possible to simply access the strings based on
locale from the json, without creating formattedMessages for them.
Thanks in advance.
Answer for question 1:
I'd say yes. You have to choose between using the declarative (e.g.: <FormattedMessage />) or the imperative api (e.g.: intl.formatMessage()).
Answer for question 2:
You could, but then why would you use react-intl then?
(You could say that you only want to use its localization methods for date, numbers, percentage.. which would be ok, but IMHO you'd have much more effort to build your own solution other than using the lib.)
I always prefer to use the declarative API, and it's a good practice to have an ID and a default message. This default message that react-intl complains is actually to help you. It's a fallback for in case you missed one translation, it defaults to this message.
I recommend using the imperative api if you want to reuse labels or if you need to use them outside react components (from my experience, these were the only cases where it could be done). You can also use the babel-plugin-react-intl to auto-extract the labels from your application and make your life pretty much easy!
What is meaning of gettext('Some text are written')?. I am using openstack, there they have use gettext(), please see the following link openstack on github
I want to know meaning of it, if they are assigning the text to the variable why they didn't use just assignment opearator
$scope.label = {
title: gettext('Instance Details'),
instanceName: gettext('Instance Name'),
availabilityZone: gettext('Availability Zone'),
instance_count: gettext('Count'),
};
It's probably related to localization. Function gettext is looking for translation of provided arguments and display them in selected locale.
As an example of translation service in angular, check https://angular-translate.github.io/
I'm new bee in mongodb.
I made a nested array document like this.
data = {
"title": "mongo community",
"description": "I am a new bee",
"topics": [{
"title": "how to find object in array",
"comments": [{
"description": "desc1"
}]
},
{
"title": "the case to use ensureIndex",
"comments": [{
"description": "before query"
},
{
"description": "If you want"
}
]
}
]
}
after that, put it in the "community"
db.community.insert(data)
so,I would like to accumulate "comments" which topics title is "how to find object in array"
then I tried,
data = db.community.find_one({"title":"mongo community","topics.title":"how to find object in array" } )
the result is
>>> print data
{
u 'topics': [{
u 'comments': [{
u 'description': u 'desc1'
}],
u 'title': u 'how to find object in array'
},
{
u 'comments': [{
u 'description': u 'before query'
},
{
u 'description': u 'If you want'
}],
u 'title': u 'the case to use ensureIndex'
}],
u '_id': ObjectId('4e6ce188d4baa71250000002'),
u 'description': u 'I am a new bee',
u 'title': u 'mongo community'
}
I don't need the topics "the case to use ensureIndex"
Whould you give me any advice.
thx.
It looks like you're embedding topics as an array all in a single document. You should try to avoid returning partial documents frequently from MongoDB. You can do it with the "fields" argument of the find method, but it isn't very easy to work with if you're doing it frequently.
So to solve this you could try to make each topic a separate document. I think that would be easier for you too. If you want to save information about the "community" for forum, put it in a separate collection. For example, you could use the following in the monbodb shell:
// ad a forum:
var forum = {
title:"mongo community",
description:"I am a new bee"
};
db.forums.save(forum);
// add first topic:
var topic = {
title: "how to find object in array",
comments: [ {description:"desc1"} ],
forum:"mongo community"
};
db.topics.save(topic);
// add second topic:
var topic = {
title: "the case to use ensureIndex",
comments: [
{description:"before query"},
{description:"If you want"}
],
forum:"mongo community"
};
db.topics.save(topic);
print("All topics:");
printjson(db.topics.find().toArray());
print("just the 'how to find object in array' topic:")
printjson(db.topics.find({title:"how to find object in array"}).toArray());
Also, see the document Trees In MongoDB about schema design in MongoDB. It happens to be using a similar schema to what you are working with and expands on it for more advanced use cases.
MongoDB operates on documents, that is, the top level documents (the things you save, update, insert, find, and find_one on). Mongo's query language lets you search within embedded objects, but will always return, update, or manipulate one (or more) of these top-level documents.
MongoDB is often called "schema-less," but something more like "(has) flexible schemas" or "(has) per-document schemas" would be a more accurate description. This is a case where your schema design -- having topics embedded directly within a community -- is not working for this particular query. However there are probably other queries that this schema supports more efficiently, like listing the topics within a community in a single query. You might want to consider the queries you want to make and re-design your schema accordingly.
A few notes on MongoDB limitations:
top-level documents are always returned (optionally with only a subset of fields, as #scott noted -- see the mongodb docs on this topic)
each document is limited to 16 megabytes of data (as of version 1.8+), so this schema will not work well if the communities have a long list of topics
For help with schema design, see the mongodb docs on schema design, Kyle Banker's video "Schema Design Basics", and Eliot Horowitz's video "Schema Design at Scale" for an introduction, tips, and considerations.