Skip to content

Commit

Permalink
Fix #21
Browse files Browse the repository at this point in the history
And also an undefined index error
  • Loading branch information
SvanteRichter committed Apr 19, 2016
1 parent 15ffa01 commit 8a61851
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function initialize()
// Twig function to translate/add labels to a forms placeholder and label attributes
$this->addTwigFunction('translate_form', 'translateForm');

$this->app['twig.loader.filesystem']->addPath(__DIR__.'/assets/views');
$this->app['twig.loader.filesystem']->addPath(__DIR__.'/views');

$this->app['config']->getFields()->addField(new Field\LocaleField());

Expand Down
7 changes: 5 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"authors": [{
"name": "Svante Richter",
"email": "[email protected]"
},{
}, {
"name": "Animal Design OG",
"email": "[email protected]"
}],
Expand All @@ -23,5 +23,8 @@
"psr-4": {
"Bolt\\Extension\\Animal\\Translate\\": ["", "src/"]
}
}
},
"extra": {
"bolt-assets": "assets"
}
}
2 changes: 1 addition & 1 deletion src/Content/LocalizedContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ public function setValue($key, $value)
private function localeHydrate($values)
{
$locales = $this->app['config']->get('general/locales');
if($locales){
if($locales && isset($values['id'])){
$locale = reset($locales);
$defaultLocaleSlug = $locale['slug'];
$currentLocale = $this->app['request']->get('_locale');
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
16 changes: 16 additions & 0 deletions views/twig/_localeswitcher.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<ul class="localeswitcher">
{% for iso, locale in locales %}
{% if app.request.get('slug') and app.request.get('_route') == 'contentlink' or app.request.get('_route') == 'pagebinding' %}
{% set newslug = get_slug_from_locale(record, iso) ?: record.slug %}
{% else %}
{% set newslug = app.request.get('slug') %}
{% endif %}
<li {% if locale.slug == app.request.get('_locale') %}class="active"{% endif %}>
<a title="{{ locale.label }}" href="{{ url(
app.request.get('_route'),
app.request.get('_route_params')|merge({_locale: locale.slug, slug: newslug })
)}}">
{{ locale.label }}
</a>
{% endfor %}
</ul>
69 changes: 69 additions & 0 deletions views/twig/boltforms_theme_translated.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{%- block choice_widget_collapsed -%}
{%- if required and placeholder is none and not placeholder_in_choices and not multiple and (attr.size is not defined or attr.size <= 1) -%}
{% set required = false %}
{%- endif -%}
<select {{ block('widget_attributes') }}{% if multiple %} multiple="multiple"{% endif %}>
{%- if placeholder is not none -%}
<option value=""{% if required and value is empty %} selected="selected"{% endif %}>{{ placeholder != '' ? (app.request.get('_locale') is null ? placeholder : l(placeholder)) }}</option>
{%- endif -%}
{%- if preferred_choices|length > 0 -%}
{% set options = preferred_choices %}
{{- block('choice_widget_options') -}}
{%- if choices|length > 0 and separator is not none -%}
<option disabled="disabled">{{ separator }}</option>
{%- endif -%}
{%- endif -%}
{%- set options = choices -%}
{{- block('choice_widget_options') -}}
</select>
{%- endblock choice_widget_collapsed -%}

{%- block choice_widget_options -%}
{% for group_label, choice in options %}
{%- if choice is iterable -%}
<optgroup label="{{ choice_translation_domain is same as(false) ? group_label : group_label|trans({}, choice_translation_domain) }}">
{% set options = choice %}
{{- block('choice_widget_options') -}}
</optgroup>
{%- else -%}
{% set attr = choice.attr %}
<option value="{{ choice.value }}" {{ block('attributes') }}{% if choice is selectedchoice(value) %} selected="selected"{% endif %}>{{ app.request.get('_locale') is null ? choice.label : l(choice.label) }}</option>
{%- endif -%}
{% endfor %}
{%- endblock choice_widget_options -%}

{%- block button_widget -%}
{%- if label is empty -%}
{%- if label_format is not empty -%}
{% set label = label_format|replace({
'%name%': name,
'%id%': id,
}) %}
{%- else -%}
{% set label = name|humanize %}
{%- endif -%}
{%- endif -%}
<button type="{{ type|default('button') }}" {{ block('button_attributes') }}>{{ app.request.get('_locale') is null ? label : l(label) }}</button>
{%- endblock button_widget -%}

{%- block form_label -%}
{% if label is not same as(false) -%}
{% if not compound -%}
{% set label_attr = label_attr|merge({'for': id}) %}
{%- endif -%}
{% if required -%}
{% set label_attr = label_attr|merge({'class': (label_attr.class|default('') ~ ' required')|trim}) %}
{%- endif -%}
{% if label is empty -%}
{%- if label_format is not empty -%}
{% set label = label_format|replace({
'%name%': name,
'%id%': id,
}) %}
{%- else -%}
{% set label = name|humanize %}
{%- endif -%}
{%- endif -%}
<label{% for attrname, attrvalue in label_attr %} {{ attrname }}="{{ attrvalue }}"{% endfor %}>{{ app.request.get('_locale') is null ? label : l(label) }}</label>
{%- endif -%}
{%- endblock form_label -%}
1 change: 1 addition & 0 deletions views/twig/trans.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{l(value)}}

0 comments on commit 8a61851

Please sign in to comment.