Guest User

Untitled

a guest
Nov 20th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. <apex:page controller="DynamicCustomLabel" contentType="application/json" showHeader="false" sidebar="false"
  2. language="{!lang}" standardStylesheets="false">{!$Label[name]}</apex:page>
  3.  
  4. public class DynamicCustomLabel {
  5. public String lang {get;set;}
  6. public String name {get;set;}
  7.  
  8. public DynamicCustomLabel(){
  9. Map<String, String> reqParams = ApexPages.currentPage().getParameters();
  10. lang = reqParams.get('lang');
  11. name = reqParams.get('name');
  12. }
  13. }
  14.  
  15. @RestResource(urlMapping='/customlabel')
  16. global with sharing class DynamicCustomLabelResource {
  17.  
  18. @HttpGet
  19. global static String getLabel() {
  20. RestRequest req = RestContext.request;
  21. String name = req.params.get('name');
  22. String lang = req.params.get('lang');
  23. try{
  24. return getLabel(name, lang);
  25. }catch(Exception e){
  26. RestContext.response.statusCode = 404;
  27. return '';
  28. }
  29. }
  30.  
  31. public static String getLabel(String labelName, String language){
  32. Pagereference r = Page.DynamicCustomLabel;
  33. r.getParameters().put('lang', language);
  34. r.getParameters().put('name', labelName);
  35. String labelValue = r.getContent().toString();
  36. return labelValue;
  37. }
  38. }
Add Comment
Please, Sign In to add comment