Can I embed a string resource into another string resource? - android

The Code A is a string resource, I hope to merge two string resources into one, just like Code B, can I do it in Android Studio 3.01?
Now I have upgraded to kotlin.
Code A
<string name="app_name">Backup Settings</string>
<string name="FeedbackEmailSubject">Report bug and suggestion about Backup Settings</string>
Code B
<string name="app_name">Backup Settings</string>
<string name="FeedbackEmailSubject">Report bug and suggestion about <string name="app_name"/></string>

I don't think there is such a way. Best way right now is below.
<string name="app_name">Backup Settings</string>
<string name="FeedbackEmailSubject">Report bug and suggestion about %1$s</string>
Observe %1$s in second string and in Code you do
getString(R.string.FeedbackEmailSubject,getString(R.string.app_name))
Which should give you out put like
Report bug and suggestion about Backup Settings

Related

Android change string language

I am using takephoto_library for selecting multiple images.
https://github.com/crazycodeboy/TakePhoto
It is working properly but as you can see in the below screenshot, the caption is in Chinese.
I found that the view control is "com.darsh.multipleimageselect.activities" and Id of this caption is in the below
actionBar.setTitle(R.string.album_view);
Is there any way to change this string to English?
Is there any way to change this string to English?
Yes, you can change all the Strings in strings.xml
https://github.com/crazycodeboy/TakePhoto/blob/master/takephoto_library/src/main/res/values/strings.xml
Change these two chinese word to english
<string name="add">确定</string>
<string name="selected">已选</string>
In English
<string name="add">confirm</string>
<string name="selected">selected</string>
Try this .
find the strings.xml(values) and strings.xml(values-en) in the library of TakePhoto .
And change the string name to the English .
In the strings.xml(values)
string name="add">确定</string>
<string name="selected">已选</string>
<string name="limit_exceeded">最多能选 %d 张</string>
And add this to the strings.xml(values-en)
string name="add">confirm</string>
<string name="selected">selected</string>
<string name="limit_exceeded">You can choose%d at most</string>
And you can change this strings.xml(values-en) and strings.xml(values)
For internationalization, android looks in different directories for the appropriate local as determined by your selection for the phone. For instance, you should see something like this:
./explorer/src/main/res/values-uk/strings.xml
./explorer/src/main/res/values-tr/strings.xml
./explorer/src/main/res/values-ru/strings.xml
./explorer/src/main/res/values-pl/strings.xml
./explorer/src/main/res/values-de/strings.xml
./explorer/src/main/res/values-ko/strings.xml
./explorer/src/main/res/values-sv/strings.xml
...
Where the translated strings are in the values-../strings as determined by the res/values/strings.xml.
In my case, res/values/strings.xml has an entry:
<string name="createnewfolder">Create new folder</string>
which is translated in values-uk/strings.xml as
<string name="createnewfolder">Нова папка</string>
You might find Localizing with Resources useful.

Get string value from XML to Java source program

I need to know if there is a way to get String type data from strings.xml (nested in resource tag)
<resources>
<string name="app_name">One World</string>
<string name="action_settings">Settings</string>
<string name="hello_world">Hello world!</string>
<string name="productInfo_lanIP">LAN IP Address :\t</string>
</resources>
and I need to get productInfo_lanIP from this and use it in my MainActivity.java to perform insertion of another string into this one.
Note: I am updating the value so I can use it to display it just after through an XML page. And I am using Android 4.2.2
you can get the strings like:
String productInfo_lanIP = getString(R.string.productInfo_lanIP);
go through this link
String mystring = getResources().getString(R.string.productInfo_lanIP);
Accept the answer if it helped you :)

how to make #symbol in string.xml for android

I am trying to make #sancorporation in my android application. I have written strings in string.xml e.g "<"string name="cor_name">sancorporation"<"/string>, but I need something like this "<"string name="cor_name">#sancorporation"<"/string>. How to take special symbol in android?
Use ascii value of # symble is 0040 so try it
for #sancorporation
<string name="mytest">#sancorporation</string>
or
<string name="mytest">\u0040 sancorporation</string>
Maybe this will help
<string name="specialChar"> "#" </string>
You can also try this
<string name="specialChar"> \# </string>
Edit:
Now I notice that you want to write #sanCorporation.
so you can use this in string.xml file:
<string name="corp"> "#sanCorp" </string>

Change the context language according to the country location in android

I am doing a project, it is going to finish but I am facing a problem to release the project. Right now, the context of the project is in English. But the requirement is like, according to the country location the context will be changed e.g Japanese, Spanish, Chinese etc. So my concern question is how to do that?
Foe English I have written like:
<string name="bookedittext">EDIT</string>
<string name="button_delete">Delete</string>
<string name="button_delete_cancel">Cancel</string>
<string name="button_back">Back</string>
<string name="progress_deleting">Deleting...</string>
<string name="share_message_conf_delete">Do you want to delete?</string>
<string name="share_message_conf_delete_all">Do you want to delete all?</string>
<string name="TEXT_SHARE_VIA">Share Via</string>
<string name="TEXT_CONTENT">Image content</string>
<string name="TEXT_SELECT_APPLICATION">Select an Application</string>
<string name="TEXT_MORE_OPTIONS">More Options</string>
<string name="TEXT_FACEBOOK">Facebook</string>
<string name="TEXT_KAKAO_TALK">Kakao Talk</string>
<string name="TEXT_SKYPE">Skype</string>
<string name="TEXT_KIK">Kik Messanger</string>
<string name="TEXT_FRING">Fring Messenger</string>
<string name="TEXT_TWITTER">Twitter</string>
<string name="TEXT_YAHOO">Yahoo Messenger</string>
<string name="TEXT_USE_FOR_DEFAULT">Use this by default action</string>
<string name="TEXT_USE_FOR_BACK">Back</string>
Please help me how to convert these to Japanese?
You can have multiple resouce files, for different locales.
Read
http://developer.android.com/guide/topics/resources/localization.html
and
http://developer.android.com/reference/java/util/Locale.html.

Internal string resource references

I wonder if it's possible to reference a XML string value in another XML String resource.
Things like the following are possible:
<string name="title">MyTitle</string>
<string name="activityTitle">#string/title</string>
But in case of an concated resource string, I found no solution yet, so what I'm searching for is the following:
<string name="title">MyTitle</string>
<string name="subTitle">#string/title - mySubTitle</string>
So far I was only able to solve it programmically via:
<string name="title">MyTitle</string>
<string name="subTitle">%1$s - mySubTitle</string>
getResources().getString(R.string.subTitle, getResources().getString(R.string.title));
I would like to keep the string references in the string.xml file itself.
What you want is not supported at this time, AFAIK.

Categories

Resources