How do I use the LocalizationService method GetString()?

Vote:
 

Lets say I have something like this in a language file,

<pagetype name="MyPage">
        
        <name>My page</name>
        <description>My very special page.</description>

        <property name="MyProperty">
          <caption>My property caption</caption>
          <help>My property help text.</help>
        </property>

</pagetype>

 

How do I get the caption and help from the pagetype property using the LocalizationService?

#78054
Dec 02, 2013 22:39
Vote:
 

Hi,

It's xpath, so I guess something like this should work:

<%= Translate("/pagetype[name=MyPage]/property[name=MyProperty]/caption") %>

    

#78055
Dec 02, 2013 23:49
Vote:
 

Thanks Johan,

but that displays [Missing text '/pagetype[name=MyPage]/property[name=MyProperty]/caption' for 'Swedish'] even though I have entered it in swedish.

@Html.Translate("/pagetype[name=MyPage]/property[name=MyProperty]/caption")

    

#78066
Dec 03, 2013 9:55
Vote:
 

It should be like this:

@Html.Translate("/pagetype[@name='MyPage']/property[@name='MyProperty']/caption")

    

#78768
Dec 03, 2013 12:16
Vote:
 

Thanks Sergii,

that isn't working either though. =(

[Missing text '/pagetype[@name='MyPage']/property[@name='MyProperty']/caption' for 'Swedish']

Could it be that there needs to be something before "/pagetype..." to specify the path to the language file?

#78769
Dec 03, 2013 12:36
Vote:
 

Yes, you have to specify the whole path. We could only guess the parts you posted here ;)

#78795
Dec 03, 2013 16:06
Vote:
 

But that doesn't seem right? What if I have a language file for each language, I don't think I should need to check which language is currently used and then write the path to that specific file, right?

#78854
Dec 04, 2013 12:06
Vote:
 

You don't need to specify the language part,  "/languages/language/", but everything after that.

#78874
Dec 04, 2013 15:02
Vote:
 

That wasn't what I meant.

Lets say I have two files in my languages directory, Translations_en.xml, Translations_sv.xml.

When we're talking about specifying the whole path, does that include the file name? Do I need to check which language is currently in use and specify the correct language file?

Perhaps an example would clear out any confusions? =)

#78875
Dec 04, 2013 15:06
Vote:
 

When we said the path, we meant the path within the xml file. You can read about it here http://en.wikipedia.org/wiki/XPath.

But you can leave out the first two nodes, "/languages/language/", because EPi selects those automatically.

#78879
Dec 04, 2013 15:32
Vote:
 

Yeah that's how I have been doing it.

I just saw that I left out a piece from the path.

@Html.Translate("/pagetype[@name='MyPage']/property[@name='MyProperty']/caption")

should be

@Html.Translate("/pagetypes/pagetype[@name='MyPage']/property[@name='MyProperty']/caption")

    

    

#78881
Edited, Dec 04, 2013 15:38
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.