How to get Object ID for dynamically created Label?? As I have to translate Label text for other languages.
Object ID is created by the interface builder and interface builder use it internally, there is no such property of UIView which gives you object id. Hence you can't access it via code (dynamically) regardless whether view is created on storyboard or at run time.
We can translate text from app using String file. In string file we can store strings we want to translate.
Ex:
Localizable.string(Hindi)
"translate" = "अनुवाद करना";
Localizable.string(English)
"translate" = "translate"
As we run app, app automatically store selected language translations from file.
Ex.[[Localisator sharedInstance] setLanguage:[language];
Related
So just started some work with an Umbraco 7 site.
The site has a custom media type. When adding media (including by dragging and dropping) and selecting this custom type the full path/url of the file added does not appear to be stored anywhere.
I've added a listener to the MediaService.Saved event and this is firing but within this method all the information I appear to have available is the id and the name of the file rather than the file itself.
I was expecting the "umbracoFile" property to be automatically populated but that doesn't appear to be the case. [I even tried editing my custom media type to have a property with alias "umbracoFile" but that just causes the Backend to crash].
Is there anyway to get the url/path of the file or to force Umbraco to set the "umbracoFile" property?
When you perform a drag and drop operation on a Folder Browser control (used in the Media section on Folders, or in the Media Picker dialog), Umbraco inspects the file type that you are dragging onto the upload area, and based on that determines the best media type to create. By default, for any known image type (png, jpg, gif, etc.) that is the Image media type, anything else is automatically assigned to the File media type.
When you hook into the MediaService.Saved event, you have access to the object representing that file in Umbraco Media, but it's already saved as a particular file type based on the description above (this has changed a little in 7.5.9 - see the below note). If you want to enable your own media type and have it set up for drag and drop, you need to dig a bit deeper.
Take a look at this: https://github.com/umbraco/Umbraco-CMS/blob/dev-v7/src/Umbraco.Web/Editors/MediaController.cs#L626-L638
Note: This applies to very recent versions of Umbraco only, as of 7.5.9 - your mileage may vary.
You may need need to look at setting the contentTypeAlias parameter of the post data when uploading the file to your preferred Media type, which may require you to create your own version of the Folder Browser data type.
Got something working in the end thanks to Robert's answer - it's fairly hacky but appears to work so I'm going to leave it here in case it helps anyone else.
Note that it uses a depreciated event handler and reflection to set private variables so I can't recommend that anyone else use it, but it might give people an idea where to start:
public void MediaService_Creating(IMediaService sender, NewEventArgs<IMedia> e)
{
int i = 0;
Type t = e.Entity.GetType();
FieldInfo[] fields = t.GetFields(BindingFlags.NonPublic | BindingFlags.Instance);
FieldInfo field = fields.First(x => x.Name == "_contentType");
MethodInfo findMediaTypeByAlias = ApplicationContext.Current.Services.MediaService
.GetType().GetMethod("FindMediaTypeByAlias", BindingFlags.NonPublic | BindingFlags.Instance);
IMediaType mediaType = (IMediaType)findMediaTypeByAlias.Invoke(
ApplicationContext.Current.Services.MediaService,
new object[] { Constants.Conventions.MediaTypes.Image });
field.SetValue(e.Entity, mediaType);
field = fields.First(x => x.Name == "ContentTypeBase");
field.SetValue(e.Entity, mediaType);
i = e.Entity.ContentTypeId;
}
The basic premise is to change the media type to Image whilst the media type is being created. By changing it in this way any extra properties for the Image media type get added and automatically populated. If a property on the custom media type shares an alias with one of the Image media type properties (such as umbracoFile) then that properties value is automatically populated meaning that it can be used in any Saving/Saved event listeners as required.
I have an event-based rule configured to fire on click of an element with a specific class. On click, I would like to capture the value of a data attribute that exists. The DTM documentation says you can capture attribute values using this syntax:
%this.data-event%
or
%this.id%
Example HTML:
On click of links with the class "test", I would like to store the value of "event name" within an eVar. When I used the above syntax however, the syntax is converted to a string and in the Adobe server call as:
v25:%this.data-event%
What is the best way to dynamically grab the value of an attribute of an HTML element on click within DTM?
DTM documentation says you can do that, but in practice I too have found that it doesn't seem to work as advertised most of the time, and will instead populate it with a literal (un-eval'd) string like that.
So what I do instead is under Conditions > Rule Conditions I create a Custom condition. In the Custom condition, I add the following:
// example to get id
_satellite.setVar('this_id',this.id);
// example to get href
_satellite.setVar('this_href',this.href);
return true;
Basically I create on-the-fly data elements using javascript, and then return true (so the condition doesn't affect the rule from triggering).
Then I use %this_id%, %this_href%, etc. syntax from the data element I created, in the Adobe Analytics section variable fields.
The easist way to capture the values of a data attribute against an eVar or prop on the element clicked using DTM is to set the input as the following:
%this.getAttribute(data-attributename)%
For example, if there was a data attribute on an element of data-social-share-destination='facebook' simply input %this.getAttribute(data-social-share-destination)%. This will then capture the value of 'facebook'
More detail on data attributes can be found at http://www.digitalbalance.com.au/our-blog/event-based-tracking-using-html5-custom-data-attributes/
I found a solution. The best way to grab the value of an attribute on click is to use this syntax:
%this.getAttribute(data-title)%
The key is to not use quotes around the attribute name AND ensure the attribute has a value.
If the attribute is missing, the expression is not replaced by an empty string as one would normally expect from experience in other platforms, but instead will display the raw un-interpolated code.
Am using Umbraco 4.11.10
Is there a standard way to create a document type property which when updated, automatically syncs with the content node name?
I know this can be done in the Properties section in the Name field but that field cannot be moved from the properties tab and it is a little out of the way - users get confused.
How is this usually done?
Wing
There are some special use umbraco field aliases. One is umbracoUrlName which will override the page url - just add it to your doctype and put it in whichever tab you want to change the url from.
EDIT
Another option would be to create a custom data type and use it to create a field that overwrites the node name. Add a text field as the UI of the custom data type; add an event that is fired whrn the textbox changes and update the name.
http://our.umbraco.org/wiki/reference/api-cheatsheet/modifying-document-properties
// Get the document by its ID
Document doc = new Document(node.Id);
// Get the properties you wish to modify by it's alias and set their value
// the value is saved in the database instantly!
doc.getProperty("name").Value = <input textbox value?;
// After modifying the document, prepare it for publishing
User author = User.GetUser(0);
doc.Publish(author);
// Tell umbraco to publish the document so the updated properties are visible on website
umbraco.library.UpdateDocumentCache(doc.Id);
I am trying to localize selectOptions on the Visual Force page.
Here is the .class code snippet:
List<SelectOption> options = new List<SelectOption>();
List<MyOption__c> dropDownValues = [SELECT Id, Display_Label_Name__c FROM MyOption__c];
for (MyOption__c val : dropDownValues) {
// Display_Label_Name__c field is the label from *.labels that needs to be translated
options.add(new SelectOption(val.Id, val.Display_Label_Name__c));
}
Here is the .page code snippet:
<apex:selectList value="{!myVal}">
<apex:selectOptions value="{!options}"/>
</apex:selectList>
Right now the dropdown displays the Display_Label_Name__c verbose. I am trying to see how I can display the translated version from the .labels file. Is it possible? If not, what's the work around?
Thank you for your responses!
All localisation of page text can be done with Custom Labels.
Enable the translation workbench with the languages you require.
Create labels for all the localisible text on the page.
Replace the page text with the labels.
Add a translation for each label.
Change your profile langauge to test.
But for your case you pull the select option text from a custom object. If the values of the select list are not expected to change frequently, less than once a week or so, then I would change to using custom labels.
Otherwise, you lose the value of Salesforce automatic language selection and have to implement something yourself.
I would recommend extending the custom object MyOption__c to have columns for all the supported languages. You could use an if/else block or dynamic apex to select the select option text.
Sample using Dynamic Apex
string language = ParseForSupportedLangauges(UserInfo.getLanguage()); // includes __c
list<sobject> dropDownValues = Database.query('SELECT Id, '+language+' FROM MyOption__c');
for (sobject val : dropDownValues) {
options.add(new SelectOption(val.get('Id'), val.get(language)));
}
ParseForSupportedLangauges() would be a custom method that checks for supported languages and assigns the default when necessary.
EDIT
Turns out there is a solution: Don't look for something until you need it, right?
Introduced in Spring '12 is the ability dynamicaly select the label to display suing array syntax. Also, the ability to create visualforce components from the controller was added but using the array syntax would be sufficient for your problem. This method would allow you to select the labels you want by using the query results from MyOption__c.
Using a repeat in visualforce to loop over the query results
<apex:repeat value="{!displayResultsValues}" var="labelName">
<apex:outputText value="{!$Label[labelName]}"/>
</apex:repeat>
Here is a good article to show the usage and syntax.
I've heard a number of similar questions for other languages, but I'm looking for a specific scenario.
My app has a Core Data model called "Record", which has a number of columns/properties like "date, column1 and column2". To keep the programming clean so I can adapt my app to multiple scenarios, input fields are mapped to a Core Data property inside a plist (so for example, I have a string variable called "dataToGet" with a value of 'column1'.
How can I retrieve the property "column1" from the Record class by using the dataToGet variable?
The Key Value Coding mechanism allows you to interact with a class's properties using string representations of the property names. So, for example, if your Record class has a property called column1, you can access that property as follows:
NSString* dataToGet = #"column1";
id value = [myRecord valueForKey:dataToGet];
You can adapt that principle to your specific needs.