How to use setLocale method of com.qaprosoft.carina.core.foundation.utils.resources.L10N class

Best Carina code snippet using com.qaprosoft.carina.core.foundation.utils.resources.L10N.setLocale

Source:L10N.java Github

copy

Full Screen

...53 54 private static SoftAssert mistakes;55 /**56 * Load L10N resource bundle corresponding to a specific locale.57 * If called setLocale function in the test, must be called to reload resources58 */ 59 public static void load() {60 // #1679: L10N: made assertion threads dependent61 mistakes = new SoftAssert();62 List<String> loadedResources = new ArrayList<String>();63 try {64 for (URL u : Resources.getResourceURLs(new ResourceURLFilter() {65 public @Override66 boolean accept(URL u) {67 String s = u.getPath();68 boolean contains = s.contains(SpecialKeywords.L10N);69 if (contains) {70 LOGGER.debug("L10N: file URL: " + u);71 }72 return contains;73 }74 })) {75 LOGGER.debug(String.format(76 "Analyzing '%s' L10N resource for loading...", u));77 /*78 * 2. Exclude localization resources like such L10N.messages_de, L10N.messages_ptBR etc...79 * Note: we ignore valid resources if 3rd or 5th char from the end is "_". As designed :(80 */81 String fileName = FilenameUtils.getBaseName(u.getPath());82 if (u.getPath().endsWith("L10N.class")83 || u.getPath().endsWith("L10N$1.class")) {84 // separate conditions to support core JUnit tests85 continue;86 }87 if (fileName.lastIndexOf('_') == fileName.length() - 388 || fileName.lastIndexOf('_') == fileName.length() - 5) {89 LOGGER.debug(String90 .format("'%s' resource IGNORED as it looks like localized resource!",91 fileName));92 continue;93 }94 /*95 * convert "file: <REPO>\target\classes\L10N\messages.properties" to "L10N.messages"96 */97 String filePath = FilenameUtils.getPath(u.getPath());98 int index = filePath.indexOf(SpecialKeywords.L10N);99 if (index == -1) {100 LOGGER.warn("Unable to find L10N pattern for " + u.getPath() + " resource!");101 continue;102 }103 String resource = filePath.substring(104 filePath.indexOf(SpecialKeywords.L10N))105 .replaceAll("/", ".")106 + fileName;107 if (!loadedResources.contains(resource)) {108 loadedResources.add(resource);109 try {110 LOGGER.debug(String.format("Adding '%s' resource...",111 resource));112 113 resBoundles.add(ResourceBundle.getBundle(resource, locale));114 LOGGER.debug(String115 .format("Resource '%s' added.", resource));116 } catch (MissingResourceException e) {117 LOGGER.debug("No resource bundle for the " + resource + " can be found", e);118 }119 } else {120 LOGGER.debug(String121 .format("Requested resource '%s' is already loaded into the ResourceBundle!",122 resource));123 }124 }125 LOGGER.debug("init: L10N bundle size: " + resBoundles.size());126 } catch (IllegalArgumentException e) {127 LOGGER.debug("L10N folder with resources is missing!");128 }129 }130 /**131 * Replace default L10N resource bundle.132 *133 * @param resources ArrayList134 *135 */ 136 public static void load(ArrayList<ResourceBundle> resources) {137 // #1679: L10N: made assertion threads dependent138 mistakes = new SoftAssert();139 resBoundles = resources;140 }141 142 /**143 * Return translated value by key for default locale.144 *145 * @param key String146 *147 * @return String148 */149 static public String getText(String key) {150 LOGGER.debug("getText: L10N bundle size: " + resBoundles.size());151 Iterator<ResourceBundle> iter = resBoundles.iterator();152 while (iter.hasNext()) {153 ResourceBundle bundle = iter.next();154 try {155 String value = bundle.getString(key);156 if (bundle.getLocale().toString().equals(locale.toString())) {157 return value;158 }159 } catch (MissingResourceException e) {160 // do nothing161 }162 }163 return key;164 }165 166 /**167 * Verify that ExtendedWebElement text is correctly localized.168 * Called automatically when an action is performed on an element169 * marked with the Localized annotation (getText, hover, etc.)170 * 171 * @param element IWebElement172 * @return boolean173 */174 public static boolean verify(IWebElement element) {175 if (!Configuration.getBoolean(Configuration.Parameter.LOCALIZATION_TESTING)) {176 return true;177 }178 179 String actualText = element.getText();180 String key = element.getName();181 String expectedText = getText(key);182 boolean isValid = actualText.contains(expectedText) && !expectedText.isEmpty();183 if (!isValid) {184 String error = "Expected: '" + expectedText + "', length=" + expectedText.length() +185 ". Actual: '" + actualText + "', length=" + actualText.length() + ".";186 LOGGER.error(error);187 mistakes.fail(error);188 String newItem = key + "=" + actualText;189 LOGGER.info("Making new localization string: " + newItem);190 missedResources.setProperty(key, actualText);191 } else {192 LOGGER.debug("Found localization text '" + actualText + " in +" + getEncoding() + " encoding: " + expectedText);193 }194 return isValid;195 }196 /**197 * Raise summarized asserts for mistakes in localization 198 */ 199 public static void assertAll() {200 mistakes.assertAll();201 }202 203 /**204 * Override default locale.205 *206 * @param loc String207 *208 */ 209 public static void setLocale(String loc) {210 LOGGER.warn("Default locale: " + locale + " was overriden by " + loc);211 locale = getLocale(loc);212 } 213 214 /**215 * Flush missed localization resources to property file.216 */217 public static void flush() {218 if (missedResources.size() == 0) {219 LOGGER.info("There are no new localization properties.");220 return;221 }222 LOGGER.info("New localization for '" + locale + "'");223 LOGGER.info("Properties: " + missedResources.toString());...

Full Screen

Full Screen

Source:L10NTest.java Github

copy

Full Screen

...24 private static final String GERMAN_VALUE = "viel Glück";25 private static final String FRANCE_VALUE = "Bonne chance";26 @Test27 public void testDefaultLocaleGetValue() {28 L10N.setLocale("");29 L10N.load();30 String value = L10N.getText(KEY);31 Assert.assertEquals(value, DEFAULT_VALUE, "Default value doesn't equal to " + DEFAULT_VALUE);32 }33 @Test34 public void testUSLocaleGetValue() {35 L10N.setLocale("en_US");36 L10N.load();37 String value = L10N.getText(KEY);38 Assert.assertEquals(value, US_VALUE, "US value doesn't equal to " + GERMAN_VALUE);39 }40 @Test41 public void testGermanyLocaleGetValue() {42 L10N.setLocale("de_DE");43 L10N.load();44 String value = L10N.getText(KEY);45 Assert.assertEquals(value, GERMAN_VALUE, "German value doesn't equal to " + GERMAN_VALUE);46 }47 @Test48 public void testFranceLocaleGetValue() {49 L10N.setLocale("fr_FR");50 L10N.load();51 String value = L10N.getText(KEY);52 Assert.assertEquals(value, FRANCE_VALUE, "France value doesn't equal to " + GERMAN_VALUE);53 }54}...

Full Screen

Full Screen

setLocale

Using AI Code Generation

copy

Full Screen

1package com.qaprosoft.carina.demo.gui.components;2import org.openqa.selenium.SearchContext;3import org.openqa.selenium.WebDriver;4import org.openqa.selenium.support.FindBy;5import org.openqa.selenium.support.PageFactory;6import com.qaprosoft.carina.core.foundation.utils.resources.L10N;7import com.qaprosoft.carina.core.gui.AbstractUIObject;8import com.qaprosoft.carina.demo.gui.pages.HomePage;9public class LanguageSelector extends AbstractUIObject {10 private LanguageSelectorItem languageSelectorItem;11 public LanguageSelector(WebDriver driver, SearchContext searchContext) {12 super(driver, searchContext);13 PageFactory.initElements(driver, this);14 }15 public LanguageSelectorItem getLanguageSelectorItem() {16 return languageSelectorItem;17 }18 public HomePage selectLanguage(String language) {19 L10N.setLocale(language);20 languageSelectorItem.selectLanguage(language);21 return new HomePage(driver);22 }23 public String getSelectedLanguage() {24 return languageSelectorItem.getSelectedLanguage();25 }26}27package com.qaprosoft.carina.demo.gui.components;28import org.openqa.selenium.SearchContext;29import org.openqa.selenium.WebDriver;30import org.openqa.selenium.support.FindBy;31import org.openqa.selenium.support.PageFactory;32import com.qaprosoft.carina.core.foundation.utils.resources.L10N;33import com.qaprosoft.carina.core.gui.AbstractUIObject;34import com.qaprosoft.carina.demo.gui.pages.HomePage;35public class LanguageSelector extends AbstractUIObject {36 private LanguageSelectorItem languageSelectorItem;37 public LanguageSelector(WebDriver driver, SearchContext searchContext) {38 super(driver, searchContext);39 PageFactory.initElements(driver, this);40 }41 public LanguageSelectorItem getLanguageSelectorItem() {42 return languageSelectorItem;43 }44 public HomePage selectLanguage(String language) {45 L10N.setLocale(language);46 languageSelectorItem.selectLanguage(language);47 return new HomePage(driver);48 }49 public String getSelectedLanguage() {50 return languageSelectorItem.getSelectedLanguage();51 }52}

Full Screen

Full Screen

setLocale

Using AI Code Generation

copy

Full Screen

1L10N.setLocale(new Locale("en", "US"));2Locale locale = L10N.getLocale();3Locale locale = L10N.getLocale("en", "US");4Locale locale = L10N.getLocale("en_US");5Locale locale = L10N.getLocale("en-US");6Locale locale = L10N.getLocale("en");7Locale locale = L10N.getLocale("en_US", "US");8Locale locale = L10N.getLocale("en_US", "US");9Locale locale = L10N.getLocale("en-US", "US");10Locale locale = L10N.getLocale("en", "US");11Locale locale = L10N.getLocale("en", "US");12Locale locale = L10N.getLocale("en_US");13Locale locale = L10N.getLocale("en-US");14Locale locale = L10N.getLocale("en");

Full Screen

Full Screen

setLocale

Using AI Code Generation

copy

Full Screen

1L10N.setLocale("en_US");2Locale locale = L10N.getLocale();3L10N.setLocale(locale);4Locale locale = L10N.getLocale();5L10N.setLocale(locale);6Locale locale = L10N.getLocale();7Locale locale = L10N.getLocale();8Locale locale = L10N.getLocale();9L10N.setLocale(locale);10Locale locale = L10N.getLocale();11L10N.setLocale(locale);12Locale locale = L10N.getLocale();13L10N.setLocale("en_US");14Locale locale = L10N.getLocale();15L10N.setLocale(locale);

Full Screen

Full Screen

setLocale

Using AI Code Generation

copy

Full Screen

1package com.qaprosoft.carina.demo;2import org.testng.annotations.Test;3import com.qaprosoft.carina.core.foundation.utils.resources.L10N;4public class DemoTest {5 public void testDemo() {6 L10N.setLocale("es");7 System.out.println(L10N.getMessage("hello.world"));8 }9}10package com.qaprosoft.carina.demo;11import org.testng.annotations.Test;12import com.qaprosoft.carina.core.foundation.utils.resources.L10N;13public class DemoTest {14 public void testDemo() {15 L10N.setLocale("en");16 System.out.println(L10N.getMessage("hello.world"));17 }18}19package com.qaprosoft.carina.demo;20import org.testng.annotations.Test;21import com.qaprosoft.carina.core.foundation.utils.resources.L10N;22public class DemoTest {23 public void testDemo() {24 L10N.setLocale("fr");25 System.out.println(L10N.getMessage("hello.world"));26 }27}28package com.qaprosoft.carina.demo;29import org.testng.annotations.Test;30import com.qaprosoft.carina.core.foundation.utils.resources.L10N;31public class DemoTest {32 public void testDemo() {33 L10N.setLocale("de");34 System.out.println(L10N.getMessage("hello.world"));35 }36}37package com.qaprosoft.carina.demo;38import org.testng.annotations.Test;39import com.qaprosoft.carina.core.foundation.utils.resources.L10N;40public class DemoTest {41 public void testDemo() {42 L10N.setLocale("ru");43 System.out.println(L10N.getMessage("hello.world"));44 }45}

Full Screen

Full Screen

setLocale

Using AI Code Generation

copy

Full Screen

1L10N.setLocale("fr_FR");2Locale locale = L10N.getLocale();3String localizedValue = L10N.getLocalizedValue("key", locale);4String localizedValue = L10N.getLocalizedValue("key");5String localizedValue = L10N.getLocalizedValue("key", "fr_FR");6String localizedValue = L10N.getLocalizedValue("key", "fr_FR", "resources");7String localizedValue = L10N.getLocalizedValue("key", "fr_FR", "resources", "messages");8String localizedValue = L10N.getLocalizedValue("key", "fr_FR", "resources", "messages", "fr");9String localizedValue = L10N.getLocalizedValue("key", "fr_FR", "resources", "messages", "fr", "properties");10String localizedValue = L10N.getLocalizedValue("key", "fr_FR", "resources", "messages", "fr", "properties", "UTF-8");

Full Screen

Full Screen

setLocale

Using AI Code Generation

copy

Full Screen

1package com.qaprosoft.carina.demo;2import org.testng.Assert;3import org.testng.annotations.Test;4import com.qaprosoft.carina.core.foundation.utils.resources.L10N;5public class L10NTest {6 public void testL10N() {7 L10N.setLocale("es");8 String localizedString = L10N.get("hello.world");9 Assert.assertEquals(localizedString, "Hola mundo");10 }11}12L10N.setLocale("es");13String localizedString = L10N.get("hello.world");14Assert.assertEquals(localizedString, "Hola mundo");15L10N.setLocale("es");16String localizedString = L10N.get("hello.world");17Assert.assertEquals(localizedString, "Hola mundo");18L10N.setLocale("es");19String localizedString = L10N.get("hello.world");20Assert.assertEquals(localizedString, "Hola mundo");21L10N.setLocale("es");22String localizedString = L10N.get("hello.world");23Assert.assertEquals(localizedString, "Hola mundo");24L10N.setLocale("es");25String localizedString = L10N.get("hello.world");26Assert.assertEquals(localizedString, "Hola mundo");27L10N.setLocale("es");28String localizedString = L10N.get("hello.world");29Assert.assertEquals(localizedString, "Hola mundo");30L10N.setLocale("es");31String localizedString = L10N.get("hello.world");32Assert.assertEquals(localizedString, "Hola mundo");33L10N.setLocale("es");34String localizedString = L10N.get("hello.world");35Assert.assertEquals(localizedString, "Hola mundo");36L10N.setLocale("

Full Screen

Full Screen

setLocale

Using AI Code Generation

copy

Full Screen

1L10N.setLocale(Locale.GERMAN);2String localizedString = L10N.getLocalizedMessage("key1");3L10N.setLocale(Locale.getDefault());4String localizedString = L10N.getLocalizedMessage("key1");5String localizedString = L10N.getLocalizedMessage("key2");6String localizedString = L10N.getLocalizedMessage("key3");7String localizedString = L10N.getLocalizedMessage("key1");8String localizedString = L10N.getLocalizedMessage("key2");9String localizedString = L10N.getLocalizedMessage("key3");

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Carina automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful