I originally misunderstood the usage of , as it seems it's only used for single-language applications.
Is there a way to pluralize message that use translations as well? For example, we have a simple line of code saying something like so:
{pluralize(formattedType, numberSelected, true)} Selected
Which would result in an output of "0 items Selected", "1 item Selected", "2 items Selected", etc.
Is there a way to incorporate similar logic with the formatjs library?
You can use MessageFormat
You can see the first example:
new IntlMessageFormat(
`You have {numPhotos, plural,
=0 {no photos.}
=1 {one photo.}
other {# photos.}
}`,
'en-US'
).format({numPhotos: 1})
Related
Is it possible to have an if/else in a FormatJS message?
Example
I have a boolean variable isDay that should determine what message is shown. When true I want to show the wording "Day" and when false I want to show Night.
// message string
message = "Day";
// React component
<FormattedMessage
id="message"
values={{isDay: true}}
/>
I want to be able to do something like:
message = "{if isDay}Day{else}Night{endif}";
I know the above is not the actual syntax, but wondering if something like this is possible with FormatJS?
Found a solution using the ICU Message select syntax.
message = "{isDay, select, true {Day} other {Night}}";
As title.
I have an array that contains some messages that I want to show to End user:
var Errors=[
"Your name is empty!",
"Your tags are empty!",
"No zip files to upload!",
];
How could I use the Modal.error call and show a dialog with break lines:
Your name is empty!
Your tags are empty!
No zip files to upload!
That is one line for a string in the array? I've tried use <br /> to the Errors.join() function call and I see the less than and great than marks; I've tried to use "\r\n" to Errors.join() but I havent' got the effects.
Sorry about that English is not my mother language. I could add some information that I didn't provide yet.
Try this:
Modal.error({
title: 'This is an error message',
content: <div dangerouslySetInnerHTML={{__html:`${Errors.join('<br/>')}`}}/>,
});
How can I pre-fill a new content with an entity relationship that I know the id? I know the item is, let's say 1234, but if I use this number like that :
#Edit.Toolbar(actions: "new", contentType: "NewsItem", prefill = new { Category = 1234 } )
It doesn't work. When I implement the code above, the form for a new item shows up but instead of having the correct item selected, I have (item not found). Obviously, my argument is not correct. So, how do I code this argument?
I also tried
Category = {1234}
Category = new {(1234}}
Category = "1234"
But nothing works. Any ideas?
We're working on enhancing this, but as of now, you are best off using the guid - as shown in the wiki: https://github.com/2sic/2sxc/wiki/razor-edit.toolbar#multiple-entities-prefil
Hope you all are going well!
I'm trying to organize a Google Calendar for different companies: they're going to propose different events to the same audience and they asked me for a Google Calendar to keep track of everything.
I'd like to know if there's a way to separate events based on users that add them
IE:
Admin_1 add Event_1
Admin_2 add Event_2
Admin_1 add Event_3
Admin_3 add Event_4
Admin_3 add Event_5
I'd like
Event_1 and Event_3 to have the same color or a label like "Admin_1: EVENT NAME".
The same for Event_4 and Event_5, created by Admin_3
Do you know how to do something like that or even if it is possible?
Thank you all for reading and answering!
Yes it is possible, just provide the colorid parameter when adding an event. You can retrieve the list of colours from the colors endpoint.
Here is a sample code for getting the list of colors:
$colors = $service->colors->get();
// Print available calendarListEntry colors.
foreach ($colors->getCalendar() as $key => $color) {
print "colorId : {$key}\n";
print " Background: {$color->getBackground()}\n";
print " Foreground: {$color->getForeground()}\n";
}
// Print available event colors.
foreach ($colors->getEvent() as $key => $color) {
print "colorId : {$key}\n";
print " Background: {$color->getBackground()}\n";
print " Foreground: {$color->getForeground()}\n";
}
You can also check this Google Calendar v3 events color.
Hope this helps.
I before the current Mongoid version 2.0.2, I was able to do
User.criteria.id( 1234 ) #=> user#1234
But now it throws a no method error. Has this been changed to something else or has it been removed?
Thank you for your input
You could always do this:
User.where(:conditions => {:id => '1234'})
Or if you didn't actually need a criteria object (and just wanted the user with id '1234') you could just do:
User.find('1234')
Found it, they (mongoid team) did remove the criteria#id selector from the latest version of mongoid. The reason why I don't use Model.find is because it doesn't do lazy loading, where criteria#id does. But back to the issue here. They replaced criteria#id with criteria#for_ids
So Model.criteria.for_ids('1234') will work