# Path: localized_fields/forms.py
# class LocalizedFieldForm(forms.MultiValueField):
#     """Form for a localized field, allows editing the field in multiple
#     languages."""
# 
#     widget = LocalizedFieldWidget
#     field_class = forms.fields.CharField
#     value_class = LocalizedValue
# 
#     def __init__(
#         self, *args, required: Union[bool, List[str]] = False, **kwargs
#     ):
#         """Initializes a new instance of :see:LocalizedFieldForm."""
# 
#         fields = []
# 
#         # Do not print initial value in html in the form of a hidden input. This will result in loss of information
#         kwargs["show_hidden_initial"] = False
# 
#         for lang_code, _ in settings.LANGUAGES:
#             field_options = dict(
#                 required=required
#                 if type(required) is bool
#                 else (lang_code in required),
#                 label=lang_code,
#             )
#             fields.append(self.field_class(**field_options))
# 
#         super(LocalizedFieldForm, self).__init__(
#             fields,
#             required=required if type(required) is bool else True,
#             require_all_fields=False,
#             *args,
#             **kwargs
#         )
# 
#         # set 'required' attribute for each widget separately
#         for field, widget in zip(self.fields, self.widget.widgets):
#             widget.is_required = field.required
# 
#     def compress(self, value: List[str]) -> LocalizedValue:
#         """Compresses the values from individual fields into a single
#         :see:LocalizedValue instance.
# 
#         Arguments:
#             value:
#                 The values from all the widgets.
# 
#         Returns:
#             A :see:LocalizedValue containing all
#             the value in several languages.
#         """
# 
#         localized_value = self.value_class()
# 
#         for (lang_code, _), value in zip(settings.LANGUAGES, value):
#             localized_value.set(lang_code, value)
# 
#         return localized_value


from django.conf import settings
from django.test import TestCase
from localized_fields.forms import LocalizedFieldForm
            assert field.label == lang_code

            if lang_code == settings.LANGUAGE_CODE:
                assert field.required
            else:
                assert not field.required

        # case required for all languages
        form = LocalizedFieldForm(required=True)
        assert form.required
        for field in form.fields:
            assert field.required

        # case optional filling
        form = LocalizedFieldForm(required=False)
        assert not form.required
        for field in form.fields:
            assert not field.required

        # case required for any language
        form = LocalizedFieldForm(required=[])
        assert form.required
        for field in form.fields:
            assert not field.required

    @staticmethod
    def test_compress():
        """Tests whether the :see:compress function is working properly."""

        input_value = [lang_name for _, lang_name in settings.LANGUAGES]

# Path: localized_fields/forms.py
# class LocalizedFieldForm(forms.MultiValueField):
#     """Form for a localized field, allows editing the field in multiple
#     languages."""
# 
#     widget = LocalizedFieldWidget
#     field_class = forms.fields.CharField
#     value_class = LocalizedValue
# 
#     def __init__(
#         self, *args, required: Union[bool, List[str]] = False, **kwargs
#     ):
#         """Initializes a new instance of :see:LocalizedFieldForm."""
# 
#         fields = []
# 
#         # Do not print initial value in html in the form of a hidden input. This will result in loss of information
#         kwargs["show_hidden_initial"] = False
# 
#         for lang_code, _ in settings.LANGUAGES:
#             field_options = dict(
#                 required=required
#                 if type(required) is bool
#                 else (lang_code in required),
#                 label=lang_code,
#             )
#             fields.append(self.field_class(**field_options))
# 
#         super(LocalizedFieldForm, self).__init__(
#             fields,
#             required=required if type(required) is bool else True,
#             require_all_fields=False,
#             *args,
#             **kwargs
#         )
# 
#         # set 'required' attribute for each widget separately
#         for field, widget in zip(self.fields, self.widget.widgets):
#             widget.is_required = field.required
# 
#     def compress(self, value: List[str]) -> LocalizedValue:
#         """Compresses the values from individual fields into a single
#         :see:LocalizedValue instance.
# 
#         Arguments:
#             value:
#                 The values from all the widgets.
# 
#         Returns:
#             A :see:LocalizedValue containing all
#             the value in several languages.
#         """
# 
#         localized_value = self.value_class()
# 
#         for (lang_code, _), value in zip(settings.LANGUAGES, value):
#             localized_value.set(lang_code, value)
# 
#         return localized_value


# Path: tests/test_form.py
from django.conf import settings
from django.test import TestCase
from localized_fields.forms import LocalizedFieldForm

            assert field.label == lang_code

            if lang_code == settings.LANGUAGE_CODE:
                assert field.required
            else:
                assert not field.required

        # case required for all languages
        form = LocalizedFieldForm(required=True)
        assert form.required
        for field in form.fields:
            assert field.required

        # case optional filling
        form = LocalizedFieldForm(required=False)
        assert not form.required
        for field in form.fields:
            assert not field.required

        # case required for any language
        form = LocalizedFieldForm(required=[])
        assert form.required
        for field in form.fields:
            assert not field.required

    @staticmethod
    def test_compress():
        """Tests whether the :see:compress function is working properly."""

        input_value = [lang_name for _, lang_name in settings.LANGUAGES]

        output_value = LocalizedFieldForm().compress(input_value)