Ember/Handlebars: Localization Helper with parameter array - ember.js

I want to localize a string that contains multiple placeholders.
E.g:
Hello %#1, today is %#2
I'd like to pass an array to the localization helper in my template like so:
{{loc "greetings" myArray}}
But that doesn't work, even though the documentation says it should.
What does work is
{{loc "greetings" "John" "Monday"}}
But the data I receive to display is an array and I don't want to store each element in a seperate variable.
How can I get the loc helper in the template to work with an array of data? Am I doing something wrong?

For the people how will fall here :
He gets his answer here : https://github.com/emberjs/ember.js/issues/16337
Loc should be/will be/is deprecated

Related

How to delete duplicate constructed objects in a list while preserving order and returning a List in dart?

I have a list of constructed objects called RecentCard which is basically an object with user id, pic, and name. I have created a list arranged in order of most recent interaction based on timestamp. However i need to get rid of the second occurence and onwards of any duplicated object. I am comparing just the ids since users may have the same name or photo, and i cannot remove duplicates from a simple list of uids because then i could lose the order of corresponding photos and names.
For example the list would look something like this :
List<RecentCard> recentCards= [RecentCard(uid:as721dn18j2,name:mike,photourl:https://sadadasd1d1),RecentCard(.....]
I have searched for solutions but all of them are dealing with like primitive types like simple lists of strings and the solutions didn't work for me. For example this post: How to delete duplicates in a dart List? list.distinct()? Read below
The first answer's link is no longer available, the next answer with sets is something i tried but it simply doesnt work i have no idea why maybe because its not a primitive type. The next answer with the queries package didn't work because i was using the list to build a listview.builder and so when i called list.length it said i couldnt call that on an iterable or something. The final solution wouldn't work because it said String is not a subtype of RecentCard.
I tried using two forloops with the second just comparing first value to the next couple but that doesnt work because if a duplicate is found, the object is removed and the length is messed up so some elements get skipped.
Any ideas? I feel like its very simple but im not sure how to do it.
You have to use Set to store seen cards and then filter away those ones that are already in the set.
final seenCards = Set<String>();
final uniqueCards = recentCards.where((card) => seenCards.add(card.uid)).toList();

How to update the values of nested dict in python?

I am new to programming and currently learning python. I am stuck when trying out dictionaries in python.
I have a normal dict with a key and the value as an empty string:
dict = {'Project_path':''},
'Target_files':'',
'default_ws':''}
I am updating the value of keys like this:
dict['project_path'] = 'Pass'
But I want to create a dict where I don't have to use long keys; instead I can map these keys to numbers so that if i want to update a dict i can do it like this:
dict = {1:{'Project_path':''},
2:{'Target_files':''},
3:{'default_ws':''}}
dict['1'] = 'pass'
It should update the value for 'project_path' as 'pass'
And after updating the values, I have to write this in a file
Is there way to do it ?
Welcome to Programming in Python! Few things here: First, using dict as a variable name is not a good idea, as this is a keyword for the whole class of dictionary objects. You can use something like, my_dict, or something like that.
Second, when you make the keys numbers and then call dict['1'] = 'pass' this looks for the string '1' in the keys, when you have declared the integer 1 as the key. Let me explain:
'1' is a string
1 is an integer.
In python these are two very different things and cannot be mixed around . That's why the value doesn't update. If you were to say dict[1] = 'pass', that should work for you and it should update the values. Note, though that this will overwrite the whole dictionary that is the current value and replace it with 'pass', if instead you just want to change the dictionary key, use
dict[1]['Project_path'] = 'pass'.
This, however seems redundant to me. It's kind of unclear exactly why you want to map integers in there (perhaps to loop through it and change values), but if you just want integers associated with it, you could just create and array of dictionaries like this:
my_array = [{"Project_path": ''}, {"Target_files":''}, {default_ws":''}]
Then, you could access them by their index starting at 0. my_array[0] is {"Project_path":''}. Again, it's kind of unclear why you want to map integers to these dicts, so it doesn't really make sense to me because this is a little redundant.
Finally, writing to a file. There's a lot of webpages out there, because there are many options when it comes to reading and writing files (like this one), but here's the short version.
with open('your_filepath.txt', 'w') as file: #note this will overwrite the current file, see the page I linked.
file.write(my_array[0]) #or whatever you want to write to it.
It's that simple, but like I said, take a look at that page to see what all your options are and choose the best one for you. Hopefully that is helpful and can get you started.

How to retrive assigned smarty template in prestashop?

Ok, so I have some smarty variables assigned on the checkout page in my shop. Problem is that when I want to use them -for example
{$address_collection.firstname}
I get an undefined index notice. I am certainly doing something wrong, but what?
on your screenshot $address_collection is array of objects, so to access to array element you need to use key, like $address_collection[124] and this element will contains address object,
where to get first name:
{$address_collection[124]->firstname}
If in smarty you want to access the array then you have to mention key of the array then you can use the values.If in your tpl file you want to print the array which you assigned then you have to write like
{var_dump($address_collection)}
Where $address_collection is the variable which from which you assigned values.
Now for access the values in your tpl file you have to mention key like:
{$address_collection['key_name']}
I hope it would help you.

SQLalchemy: iterate through raw SQL query in template

Have a code in function, which renders ResultProxy (as I understand), to template, like this:
query = db_session.execute(serious_business_query) #raw sql
return render_template('result.html', query=query)
I want to iterate through it in my template, but see nothing. How can I iterate through ResultProxy object? Or what should I pass to template to simply iterate through it?
Links to docs are OK, cant find what I need.
You might want to try this suggestion https://stackoverflow.com/a/17987782/1307985
and when you fill in a list from the cursor then to pass it to the template.
I am guessing, but probably the jinja2 template does not know how to itterate over cursor or query like object so it have to be converted to a list object.

MFC treeview control : looking for a foolproof way to deal with data

Maybe I am doing something wrong here. I am using a treeview control , which I populate with data. The data (integers mainly) are transformed to CStrings for that matter. When the user clicks on an item, I can read the CString, but then have to parse it in order to get the data .
Several times I have changed the way the data appears on the screen ,and then everything breaks, and I need to rewrite the parsing function. I wonder if there is a better way to do this...
EDIT : The treeview is being populated with items from a std::vector. If I could get the treeview to return an index in the vector instead of a CString , this would fit me perfectly.
You can use CTreeCtrl::SetItemData to associate an arbitrary data value with a tree item, and CTreeCtrl::GetItemData to retrieve this value. Typically you use SetItemData to store a pointer to an object, but in your case you could use this to store the integer values directly.
I hope this helps!
If you change the way you set/get your data in the tree, then you will have to change the way you format and and parse it.
Normally, you should only have 2 functions, the setter and the parser, so it should not be a big issue
I don't think there is a way to make it really faster or cleaner.