code: @Override
      public Locale getLocaleForResource(CmsObject cms, CmsResource resource, List<Locale> availableLocales) {
  
          Locale result = null;
          List<Locale> defaultLocales = OpenCms.getLocaleManager().getDefaultLocales(cms, resource);
          if ((availableLocales != null) && (availableLocales.size() > 0)) {
              result = OpenCms.getLocaleManager().getBestMatchingLocale(
                  defaultLocales.get(0),
                  defaultLocales,
                  availableLocales);
          }
          if (result == null) {
              result = ((availableLocales != null) && availableLocales.isEmpty())
              ? availableLocales.get(0)
              : defaultLocales.get(0);
          }
          return result;
      }
docs: Returns the language locale for the given resource in this index.<p>
  
  @param cms the current OpenCms user context
  @param resource the resource to check
  @param availableLocales a list of locales supported by the resource
  
  @return the language locale for the given resource in this index