Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <apex:page controller="DynamicCustomLabel" contentType="application/json" showHeader="false" sidebar="false"
- language="{!lang}" standardStylesheets="false">{!$Label[name]}</apex:page>
- public class DynamicCustomLabel {
- public String lang {get;set;}
- public String name {get;set;}
- public DynamicCustomLabel(){
- Map<String, String> reqParams = ApexPages.currentPage().getParameters();
- lang = reqParams.get('lang');
- name = reqParams.get('name');
- }
- }
- @RestResource(urlMapping='/customlabel')
- global with sharing class DynamicCustomLabelResource {
- @HttpGet
- global static String getLabel() {
- RestRequest req = RestContext.request;
- String name = req.params.get('name');
- String lang = req.params.get('lang');
- try{
- return getLabel(name, lang);
- }catch(Exception e){
- RestContext.response.statusCode = 404;
- return '';
- }
- }
- public static String getLabel(String labelName, String language){
- Pagereference r = Page.DynamicCustomLabel;
- r.getParameters().put('lang', language);
- r.getParameters().put('name', labelName);
- String labelValue = r.getContent().toString();
- return labelValue;
- }
- }
Add Comment
Please, Sign In to add comment