#!/bin/bash

. /etc/sysconfig/i18n

function rm_locale() {
  # $1 - dir 
  # $2  - condition
  find "$1" -maxdepth 1 -type d | grep -v $2| while read dirname; do
    if [ "x$dirname" = "x$1" ]; then
	continue
    fi
    echo "Remove:" $dirname
    rm -rf $dirname
  done
}

function rm_gnomehelp() {
  # $1 - dir 
  # $2  - condition
  find "$1" -maxdepth 1 -type d | while read dirname; do
    if [ "x$dirname" = "x$1" ]; then
	continue
    fi
    rm_locale $dirname $2
  done
}

condition="ru_RU\|uk_UA"
condition2="C\|ru\|uk"

for segment in `echo $SUPPORTED| sed -e "s/:/ /g"`; do
    segment=`echo $segment| grep "^[a-z][a-z]_[A-Z][A-Z]$"`
    if [ "x$segment" = "x" ]; then
	continue
    fi
    country=`echo $segment| sed -e "s/_[A-Z][A-Z]//"`
    
    condition=$condition"\|$segment"
    condition2=$condition2"\|$country"
done

condition3=$condition2"\|man[^/]"

rm_locale /usr/lib/locale "$condition"
rm_locale /usr/share/locale "$condition2"
rm_locale /usr/share/man "$condition3"
rm_gnomehelp /usr/share/gnome/help "$condition2"


