code: public void attachLocaleGroup(CmsResource secondaryPage, CmsResource primaryPage) throws CmsException {
  
          if (secondaryPage.getStructureId().equals(primaryPage.getStructureId())) {
              throw new IllegalArgumentException(
                  "A page can not be linked with itself as a locale variant: " + secondaryPage.getRootPath());
          }
          CmsLocaleGroup group = readLocaleGroup(secondaryPage);
          if (group.isRealGroup()) {
              throw new IllegalArgumentException(
                  "The page " + secondaryPage.getRootPath() + " is already part of a group. ");
          }
  
          // TODO: Check for redundant locales
  
          CmsLocaleGroup targetGroup = readLocaleGroup(primaryPage);
          CmsLockActionRecord record = CmsLockUtil.ensureLock(m_cms, secondaryPage);
          try {
              m_cms.deleteRelationsFromResource(
                  secondaryPage,
                  CmsRelationFilter.ALL.filterType(CmsRelationType.LOCALE_VARIANT));
              m_cms.addRelationToResource(
                  secondaryPage,
                  targetGroup.getPrimaryResource(),
                  CmsRelationType.LOCALE_VARIANT.getName());
          } finally {
              if (record.getChange() == LockChange.locked) {
                  m_cms.unlockResource(secondaryPage);
              }
          }
      }
docs: Adds a resource to a locale group.<p>
  
  Note: This is a low level method that is hard to use correctly. Please use attachLocaleGroupIndirect if at all possible.
  
  @param secondaryPage the page to add
  @param primaryPage the primary resource of the locale group which the resource should be added to
  @throws CmsException if something goes wrong