com.android.ide.common.resources.configuration.LocaleQualifier Java Examples

The following examples show how to use com.android.ide.common.resources.configuration.LocaleQualifier. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TranslationDetector.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
/** Look up the language for the given folder name */
private static String getLanguageTag(String name) {
    if (FD_RES_VALUES.equals(name)) {
        return null;
    }

    FolderConfiguration configuration = FolderConfiguration.getConfigForFolder(name);
    if (configuration != null) {
      LocaleQualifier locale = configuration.getLocaleQualifier();
      if (locale != null && !locale.hasFakeValue()) {
          return locale.getTag();
      }
    }

    return null;
}
 
Example #2
Source File: ResourceRepository.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns the sorted list of languages used in the resources.
 */
@NonNull
public SortedSet<String> getLanguages() {
    ensureInitialized();

    SortedSet<String> set = new TreeSet<String>();

    Collection<List<ResourceFolder>> folderList = mFolderMap.values();
    for (List<ResourceFolder> folderSubList : folderList) {
        for (ResourceFolder folder : folderSubList) {
            FolderConfiguration config = folder.getConfiguration();
            LocaleQualifier locale = config.getLocaleQualifier();
            if (locale != null) {
                set.add(locale.getLanguage());
            }
        }
    }

    return set;
}
 
Example #3
Source File: ResourceRepository.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns the sorted list of regions used in the resources with the given language.
 * @param currentLanguage the current language the region must be associated with.
 */
@NonNull
public SortedSet<String> getRegions(@NonNull String currentLanguage) {
    ensureInitialized();

    SortedSet<String> set = new TreeSet<String>();

    Collection<List<ResourceFolder>> folderList = mFolderMap.values();
    for (List<ResourceFolder> folderSubList : folderList) {
        for (ResourceFolder folder : folderSubList) {
            FolderConfiguration config = folder.getConfiguration();

            // get the language
            LocaleQualifier locale = config.getLocaleQualifier();
            if (locale != null && currentLanguage.equals(locale.getLanguage())
                    && locale.getRegion() != null) {
                set.add(locale.getRegion());
            }
        }
    }

    return set;
}
 
Example #4
Source File: ResourceRepository.java    From NBANDROID-V2 with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the sorted list of languages used in the resources.
 */
@NonNull
public SortedSet<String> getLanguages() {
    ensureInitialized();

    SortedSet<String> set = new TreeSet<String>();

    Collection<List<ResourceFolder>> folderList = mFolderMap.values();
    for (List<ResourceFolder> folderSubList : folderList) {
        for (ResourceFolder folder : folderSubList) {
            FolderConfiguration config = folder.getConfiguration();
            LocaleQualifier locale = config.getLocaleQualifier();
            if (locale != null && locale.hasLanguage()) {
                set.add(locale.getLanguage());
            }
        }
    }

    return set;
}
 
Example #5
Source File: ResourceRepository.java    From NBANDROID-V2 with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the sorted list of regions used in the resources with the given language.
 *
 * @param currentLanguage the current language the region must be associated with.
 */
@NonNull
public SortedSet<String> getRegions(@NonNull String currentLanguage) {
    ensureInitialized();

    SortedSet<String> set = new TreeSet<String>();

    Collection<List<ResourceFolder>> folderList = mFolderMap.values();
    for (List<ResourceFolder> folderSubList : folderList) {
        for (ResourceFolder folder : folderSubList) {
            FolderConfiguration config = folder.getConfiguration();

            // get the language
            LocaleQualifier locale = config.getLocaleQualifier();
            if (locale != null && currentLanguage.equals(locale.getLanguage())
                    && locale.getRegion() != null) {
                set.add(locale.getRegion());
            }
        }
    }

    return set;
}
 
Example #6
Source File: GeneratedResourceClassifier.java    From intellij with Apache License 2.0 6 votes vote down vote up
private static boolean mayHaveNonStringTranslations(String dirName) {
  // String translations only sit in the values-xx-rYY directories, so we can rule out other
  // directories quickly.
  if (!dirName.contains(SdkConstants.RES_QUALIFIER_SEP)) {
    return true;
  }
  if (ResourceFolderType.getFolderType(dirName) != ResourceFolderType.VALUES) {
    return true;
  }
  FolderConfiguration config = FolderConfiguration.getConfigForFolder(dirName);
  // Conservatively say it's interesting if there is an unrecognized configuration.
  if (config == null) {
    return true;
  }
  // If this is a translation mixed with something else, consider it a translation directory.
  boolean hasTranslation = false;
  for (ResourceQualifier qualifier : config.getQualifiers()) {
    if (qualifier instanceof LocaleQualifier) {
      hasTranslation = true;
    }
  }
  return !hasTranslation;
}
 
Example #7
Source File: LintUtils.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns the locale for the given parent folder.
 *
 * @param parent the name of the parent folder
 * @return null if the locale is not known, or a locale qualifier providing the language
 *    and possibly region
 */
@Nullable
public static LocaleQualifier getLocale(@NonNull String parent) {
    if (parent.indexOf('-') != -1) {
        FolderConfiguration config = FolderConfiguration.getConfigForFolder(parent);
        if (config != null) {
            return config.getLocaleQualifier();
        }
    }
    return null;
}
 
Example #8
Source File: LintUtils.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns the locale for the given context.
 *
 * @param context the context to look up the locale for
 * @return null if the locale is not known, or a locale qualifier providing the language
 *    and possibly region
 */
@Nullable
public static LocaleQualifier getLocale(@NonNull XmlContext context) {
    Element root = context.document.getDocumentElement();
    if (root != null) {
        String locale = root.getAttributeNS(TOOLS_URI, ATTR_LOCALE);
        if (locale != null && !locale.isEmpty()) {
            return getLocale(locale);
        }
    }

    return getLocale(context.file.getParentFile().getName());
}
 
Example #9
Source File: LintUtils.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Check whether the given resource file is in an English locale
 * @param context the XML context for the resource file
 * @param assumeForBase whether the base folder (e.g. no locale specified) should be
 *                      treated as English
 */
public static boolean isEnglishResource(@NonNull XmlContext context, boolean assumeForBase) {
    LocaleQualifier locale = LintUtils.getLocale(context);
    if (locale == null) {
        return assumeForBase;
    } else {
        return "en".equals(locale.getLanguage());  //$NON-NLS-1$
    }
}
 
Example #10
Source File: TypoDetector.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/** Look up the locale and region from the given parent folder name and store it
 * in {@link #mLanguage} and {@link #mRegion} */
private void initLocale(@NonNull String parent) {
    mLanguage = null;
    mRegion = null;

    if (parent.equals(FD_RES_VALUES)) {
        return;
    }

    LocaleQualifier locale = LintUtils.getLocale(parent);
    if (locale != null) {
        mLanguage = locale.getLanguage();
        mRegion = locale.hasRegion() ? locale.getRegion() : null;
    }
}
 
Example #11
Source File: AbstractResourceRepository.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns the sorted list of languages used in the resources.
 */
@NonNull
public SortedSet<String> getLanguages() {
    SortedSet<String> set = new TreeSet<String>();

    // As an optimization we could just look for values since that's typically where
    // the languages are defined -- not on layouts, menus, etc -- especially if there
    // are no translations for it
    Set<String> qualifiers = Sets.newHashSet();

    synchronized (ITEM_MAP_LOCK) {
        for (ListMultimap<String, ResourceItem> map : getMap().values()) {
            for (ResourceItem item : map.values()) {
                qualifiers.add(item.getQualifiers());
            }
        }
    }

    for (String s : qualifiers) {
        FolderConfiguration configuration = FolderConfiguration.getConfigForQualifierString(s);
        if (configuration != null) {
            LocaleQualifier locale = configuration.getLocaleQualifier();
            if (locale != null) {
                set.add(locale.getLanguage());
            }
        }
    }

    return set;
}
 
Example #12
Source File: AbstractResourceRepository.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns the sorted list of languages used in the resources.
 */
@NonNull
public SortedSet<LocaleQualifier> getLocales() {
    SortedSet<LocaleQualifier> set = new TreeSet<LocaleQualifier>();

    // As an optimization we could just look for values since that's typically where
    // the languages are defined -- not on layouts, menus, etc -- especially if there
    // are no translations for it
    Set<String> qualifiers = Sets.newHashSet();

    synchronized (ITEM_MAP_LOCK) {
        for (ListMultimap<String, ResourceItem> map : getMap().values()) {
            for (ResourceItem item : map.values()) {
                qualifiers.add(item.getQualifiers());
            }
        }
    }

    for (String s : qualifiers) {
        FolderConfiguration configuration = FolderConfiguration.getConfigForQualifierString(s);
        if (configuration != null) {
            LocaleQualifier locale = configuration.getLocaleQualifier();
            if (locale != null) {
                set.add(locale);
            }
        }
    }

    return set;
}
 
Example #13
Source File: AbstractResourceRepository.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns the sorted list of regions used in the resources with the given language.
 * @param currentLanguage the current language the region must be associated with.
 */
@NonNull
public SortedSet<String> getRegions(@NonNull String currentLanguage) {
    SortedSet<String> set = new TreeSet<String>();

    // As an optimization we could just look for values since that's typically where
    // the languages are defined -- not on layouts, menus, etc -- especially if there
    // are no translations for it
    Set<String> qualifiers = Sets.newHashSet();
    synchronized (ITEM_MAP_LOCK) {
        for (ListMultimap<String, ResourceItem> map : getMap().values()) {
            for (ResourceItem item : map.values()) {
                qualifiers.add(item.getQualifiers());
            }
        }
    }

    for (String s : qualifiers) {
        FolderConfiguration configuration = FolderConfiguration.getConfigForQualifierString(s);
        if (configuration != null) {
            LocaleQualifier locale = configuration.getLocaleQualifier();
            if (locale != null && locale.getRegion() != null
                    && locale.getLanguage().equals(currentLanguage)) {
                set.add(locale.getRegion());
            }
        }
    }

    return set;
}
 
Example #14
Source File: ConfigGenerator.java    From NBANDROID-V2 with Apache License 2.0 5 votes vote down vote up
public FolderConfiguration getFolderConfig() {
    FolderConfiguration config = new FolderConfiguration();
    // config.createDefault();
    config.setDensityQualifier(new DensityQualifier(mDensity));
    config.setNavigationMethodQualifier(new NavigationMethodQualifier(mNavigation));
    if (mScreenWidth > mScreenHeight) {
        config.setScreenDimensionQualifier(new ScreenDimensionQualifier(mScreenWidth,
                mScreenHeight));
    } else {
        config.setScreenDimensionQualifier(new ScreenDimensionQualifier(mScreenHeight,
                mScreenWidth));
    }
    config.setScreenRatioQualifier(new ScreenRatioQualifier(mRatio));
    config.setScreenSizeQualifier(new ScreenSizeQualifier(mSize));
    config.setTextInputMethodQualifier(new TextInputMethodQualifier(mKeyboard));
    config.setTouchTypeQualifier(new TouchScreenQualifier(mTouchScreen));
    config.setKeyboardStateQualifier(new KeyboardStateQualifier(mKeyboardState));
    config.setScreenOrientationQualifier(new ScreenOrientationQualifier(mOrientation));

    config.updateScreenWidthAndHeight();

    // some default qualifiers.
    config.setUiModeQualifier(new UiModeQualifier(UiMode.NORMAL));
    config.setNightModeQualifier(new NightModeQualifier(NightMode.NOTNIGHT));
    config.setCountryCodeQualifier(new CountryCodeQualifier());
    config.setLayoutDirectionQualifier(new LayoutDirectionQualifier());
    config.setNetworkCodeQualifier(new NetworkCodeQualifier());
    config.setLocaleQualifier(new LocaleQualifier());
    config.setVersionQualifier(new VersionQualifier(28));
    return config;
}