SCHEMA ISO13584_IEC61360_language_resource_schema;

REFERENCE FROM support_resource_schema(identifier, label, text); 
    
 


TYPE language_code = identifier; 
END_TYPE; -- language_code


ENTITY global_language_assignment;
    language: language_code;
END_ENTITY; -- global_language_assignment


ENTITY present_translations; 
    language_codes: LIST [1:?] OF UNIQUE language_code;
UNIQUE
    UR1: language_codes;
END_ENTITY; -- present_translations


TYPE translatable_label = SELECT(label, translated_label);
END_TYPE; -- translatable_label


ENTITY translated_label; 
    labels: LIST [1:?] OF label;
    languages: present_translations; 
WHERE
    WR1: SIZEOF(labels) = SIZEOF(languages.language_codes);
END_ENTITY; -- translated_label


TYPE translatable_text = SELECT(text, translated_text);
END_TYPE; -- translatable_text


ENTITY translated_text; 
    texts: LIST [1:?] OF text;
    languages: present_translations; 
WHERE
    WR1: SIZEOF(texts) = SIZEOF(languages.language_codes);
END_ENTITY; -- translated_text


FUNCTION check_label_length(l: translatable_label;
    l_length: INTEGER): BOOLEAN;

IF 'ISO13584_IEC61360_LANGUAGE_RESOURCE_SCHEMA.TRANSLATED_LABEL' 
    IN TYPEOF(l) 
THEN 
    REPEAT i :=1 TO SIZEOF(l.labels);
        IF LENGTH(l.labels[i]) > l_length 
        THEN
            RETURN(FALSE);
        END_IF;
    END_REPEAT;

    RETURN(TRUE);

ELSE 
    RETURN(LENGTH(l) <= l_length); 
END_IF;
END_FUNCTION; -- check_label_length 


FUNCTION check_text_length(t: translatable_text;
    t_length: INTEGER): BOOLEAN;

IF 'ISO13584_IEC61360_LANGUAGE_RESOURCE_SCHEMA.TRANSLATED_TEXT' 
    IN TYPEOF(t) 
THEN 
    REPEAT i :=1 TO SIZEOF(t.texts);
        IF LENGTH(t.texts[i]) > t_length 
        THEN
            RETURN(FALSE);
        END_IF;
    END_REPEAT;

    RETURN(TRUE);

ELSE 
    RETURN(LENGTH(t) <= t_length); 
END_IF;
END_FUNCTION; -- check_text_length 


RULE single_language_assignment FOR(global_language_assignment);
WHERE
    SIZEOF(global_language_assignment) <= 1;
END_RULE; -- single_language_assignment


END_SCHEMA; -- ISO13584_IEC61360_language_resource_schema
