001/* 002 * Copyright 2012 Anyware Services 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.ametys.cms.languages; 018 019import org.ametys.runtime.i18n.I18nizableText; 020 021/** 022 * A language representation 023 */ 024public class Language 025{ 026 private String _code; 027 private I18nizableText _label; 028 029 /** 030 * Creates a language 031 * @param code The code of the language 032 * @param label The label of the language 033 */ 034 public Language(String code, I18nizableText label) 035 { 036 _code = code; 037 _label = label; 038 } 039 040 /** 041 * Get the language code 042 * @return The code 043 */ 044 public String getCode() 045 { 046 return _code; 047 } 048 049 /** 050 * Get the language label 051 * @return The label 052 */ 053 public I18nizableText getLabel() 054 { 055 return _label; 056 } 057 058 /** 059 * Get the small icon flag image 060 * @return The path relative to the webapps 061 */ 062 public String getSmallIcon() 063 { 064 return getIcon("small"); 065 } 066 067 /** 068 * Get the medium icon flag image 069 * @return The path relative to the webapps 070 */ 071 public String getMediumIcon() 072 { 073 return getIcon("medium"); 074 } 075 076 /** 077 * Get the large icon flag image 078 * @return The path relative to the webapps 079 */ 080 public String getLargeIcon() 081 { 082 return getIcon("large"); 083 } 084 085 private String getIcon(String size) 086 { 087 if (_label.isI18n() && _label.getCatalogue().startsWith("plugin.")) 088 { 089 return "/plugins/" + _label.getCatalogue().substring("plugin.".length()) + "/resources/img/flag/" + size + "/flag-" + _code + ".png"; 090 } 091 else 092 { 093 return "/plugins/cms/resources_flag/" + size + "/flag-" + _code + ".png"; 094 } 095 } 096}