Skip to content

Commit

Permalink
add persian translation
Browse files Browse the repository at this point in the history
  • Loading branch information
yaghoubi committed Oct 8, 2024
1 parent 3526012 commit a499b6f
Show file tree
Hide file tree
Showing 14 changed files with 267 additions and 2,756 deletions.
Binary file modified django_daisy/locale/fa/LC_MESSAGES/django.mo
Binary file not shown.
639 changes: 191 additions & 448 deletions django_daisy/locale/fa/LC_MESSAGES/django.po

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions django_daisy/module_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
app_path / "static",
]

settings.LOCALE_PATHS += [
app_path / "locale"
]

settings.X_FRAME_OPTIONS = 'SAMEORIGIN'

if not hasattr(settings, 'APPS_REORDER'):
Expand Down
4 changes: 4 additions & 0 deletions django_daisy/static/admin/css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,7 @@ a.tab-active i {
.ts-wrapper .ts-control {
@apply bg-base-200 border border-base-300 !important;
}

.ts-wrapper .ts-control > div{
@apply border-base-300 border bg-base-300 text-base-content !important ;
}
2 changes: 1 addition & 1 deletion django_daisy/static/admin/css/tailwind.css

Large diffs are not rendered by default.

52 changes: 34 additions & 18 deletions django_daisy/static/admin/js/query_filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,30 @@ const QueryModule = (function () {
let queryMap = {};

function extractValueFromQueryString(queryString, data_key) {
const result = {}
const params = new URLSearchParams(queryString);
let val = null
params.forEach((v, k) => {
if (k.startsWith(data_key)) {
result[k] = v; // Store matching key-value pairs
val = v;
}
})
return val
}

return result
function extractTheShitOutOfIt(queryString, data_key) {
const all_params = new URLSearchParams(queryString);
let this_params = ""
all_params.forEach((v, k) => {
v = encodeURIComponent(v)
if (k.startsWith(data_key)) {
this_params += `&${k}=${v}`;
}
})
return this_params
}


function addOrUpdateQueryParameter(value, key) {
function addOrUpdateQueryParameter(value, key, option) {
key = key.replace('__exact', '__in')
if (queryMap[key]) {
// Append new value to existing key with a comma separator
Expand All @@ -29,37 +40,42 @@ const QueryModule = (function () {
}
}

function buildQueryString() {
return '?' + Object.keys(queryMap).map(key => {
const formattedKey = key.replace('__exact', '__in');
const formattedVal = encodeURIComponent(queryMap[key])
function buildQueryString(queryObj) {
return '?' + Object.keys(queryObj).map(key => {
let formattedKey = key.replace('__exact', '__in');
let formattedVal = encodeURIComponent(queryObj[key])
return `${formattedKey}=${formattedVal}`;
}).join('&');
}


function applyFilters() {
const urlParams = new URLSearchParams(window.location.search);
queryMap = {};
const facets = urlParams.get('_facets');
if (facets) {
queryMap['_facets'] = true
}

let queryString = "";

let single_query_string = ""
$('.filter-select').each(function () {
const selectedValues = $(this).val();
const dataKey = $(this).data('key');

if (selectedValues) {
let selectedValues = $(this).val();
let dataKey = $(this).data('key');
if (dataKey && dataKey.includes('__exact') && selectedValues) {
selectedValues.forEach(option => {
queryMap = {...queryMap, ...extractValueFromQueryString(option, dataKey)}
let v = extractValueFromQueryString(option, dataKey)
addOrUpdateQueryParameter(v, dataKey, option)
});
} else if (dataKey && selectedValues) {
if (selectedValues instanceof Array) {
selectedValues = selectedValues[0]
}
single_query_string += extractTheShitOutOfIt(selectedValues, dataKey)
}
});

queryString = buildQueryString();
console.log(queryString);
let multQueryString = buildQueryString(queryMap);

let queryString = multQueryString + single_query_string
window.location.href = queryString;
}

Expand Down
6 changes: 5 additions & 1 deletion django_daisy/templates/admin/base.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{% load i18n %}
{% load static %}
{% get_current_language as LANGUAGE_CODE %}{% get_current_language_bidi as LANGUAGE_BIDI %}

<!DOCTYPE html>
<html data-theme="light" class="custom-scrollbars" lang="{{ LANGUAGE_CODE|default:"en-us" }}"
{% if LANGUAGE_BIDI %}dir="rtl"
Expand Down Expand Up @@ -60,7 +62,9 @@
<div id="content" class="w-full h-full main-wrapper transition-all duration-200 ease-in-out">
<div class="h-full flex flex-col">
{% block top-navbar %}
{% include 'admin/parts/navbar.html' %}
{% if not is_popup %}
{% include 'admin/parts/navbar.html' %}
{% endif %}
{% endblock %}

<div class="content-wrapper h-full max-md:p-3 p-5">
Expand Down
6 changes: 3 additions & 3 deletions django_daisy/templates/admin/change_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
</div>
</div>
{% endif %}
<div role="tablist" class="w-full items-start tabs tabs-lifted overflow-x-auto">
<div role="tablist" class="w-full items-start tabs overflow-visible tabs-lifted">
{% block field_sets %}
<a class="indicator tab tab-active">
{{ fieldset.name|default:opts.object_name }}
Expand All @@ -101,7 +101,7 @@

<div role="tabpanel" class="tab-content">
{% for fieldset in adminform %}
<fieldset class="mb-3 collapse w-full collapse-arrow fieldset card bg-base-100 p-1">
<fieldset class="mb-3 ltr:!rounded-tl-none rtl:!rounded-tr-none collapse w-full collapse-arrow overflow-visible fieldset card bg-base-100 p-1">
<input type="checkbox" name="fieldsets-{{ forloop.counter }}" checked/>
<div class="collapse-title text-xl font-medium">
{{ fieldset.name|default:opts.object_name }}
Expand Down Expand Up @@ -156,7 +156,7 @@
</div>

{% block submit_buttons_bottom %}
<div class="xl:w-96 w-full xl:mt-5 z-10 sticky bottom-2">
<div class="xl:w-96 w-full xl:mt-5 z-10 sticky max-lg:fixed max-lg:-ml-3 bottom-0">
<div>
{% submit_row %}
</div>
Expand Down
6 changes: 4 additions & 2 deletions django_daisy/templates/admin/filter.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
{% load i18n %}
<li class="card">
<label class="navbar-nav-link dropdown-toggle legitRipple">
<b class="text-sm mb-1 inline-block capitalize">{% blocktranslate with filter_title=title %}{{ filter_title }} {% endblocktranslate %}:</b>
<select multiple class="filter-select" data-key="{% firstof spec.lookup_kwarg spec.parameter_name spec.field_generic %}">
<b class="text-sm mb-1 inline-block capitalize">
{% blocktranslate with filter_title=title %}{{ filter_title }} {% endblocktranslate %}:</b>
<select {% is_multiple_filter_choice spec %} class="filter-select"
data-key="{% firstof spec.lookup_kwarg spec.parameter_name spec.field_generic %}">
{% for choice in choices %}
<option {% is_active_choice choice spec %} value="{{ choice.query_string|iriencode }}">
{{ choice.display }}
Expand Down
4 changes: 2 additions & 2 deletions django_daisy/templates/admin/submit_line.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@
<button class="btn-sm bg-blue-300 text-black btn rounded-md legitRipple" type="submit" name="_continue">
{% if can_change %}{% translate 'Save and continue editing' %}{% else %}
{% translate 'Save and view' %}{% endif %}
<i class="fas fa-sync"></i>
<i class="max-sm:!hidden fas fa-sync"></i>
</button>
{% endif %}
{% if show_save_and_add_another %}
<button class="btn-sm bg-blue-300 text-black rounded-md btn legitRipple" type="submit"
name="_addanother">
{% translate 'Save and add another' %}
<i class="fas fa-plus-circle"></i>
<i class="max-sm:!hidden fas fa-plus-circle"></i>
</button>
{% endif %}
{% if show_delete_link and original or can_delete_popup %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@
</div>
<!-- Dropdown for links -->
{% if can_change_related or can_add_related or can_delete_related or can_view_related %}
<div onclick="isElementInViewport(this)" class="dropdown dropdown-right dropdown-hover">
<div class="dropdown dropdown-end dropdown-open dropdown-hover">
{% block links %}
{% spaceless %}

<!-- Render the dropdown button only if there are related actions available -->
<div tabindex="0" role="button" class="btn btn-sm dropdown-btn">
{% trans "Options" %}
</div>
<ul tabindex="0" class="dropdown-content menu bg-base-100 rounded-box z-10 w-52 p-2 shadow">
<ul tabindex="0" class="dropdown-content menu bg-base-100 rounded-box z-20 w-52 p-2 shadow">
{% if can_change_related %}
<li>
<a class="related-widget-wrapper-link change-related" id="change_id_{{ name }}"
Expand Down
2 changes: 1 addition & 1 deletion django_daisy/templates/django/forms/widgets/input.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% load dash_tags %}
{% with widget=widget|apply_class_to_widget:'input w-full min-w-24 focus:outline-0 transition-all input-sm input-bordered focus:outline-offset-0' %}
{% with widget=widget|apply_class_to_widget:'input w-full focus:outline-0 transition-all input-sm input-bordered focus:outline-offset-0' %}
<input type="{{ widget.type }}" name="{{ widget.name }}" {% if widget.value != None %}
value="{{ widget.value|stringformat:'s' }}"{% endif %}{% include "django/forms/widgets/attrs.html" %} >
{% endwith %}
16 changes: 16 additions & 0 deletions django_daisy/templatetags/dash_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ def get_value_by_key(query, key):

@register.simple_tag
def is_active_choice(choice, spec):
try:
if spec.lookup_kwarg not in choice['query_string']:
return ''
except Exception:
pass

if choice.get('selected'):
return 'selected'

Expand Down Expand Up @@ -130,3 +136,13 @@ def get_active_filters_count(cl):
return len(cl.filter_params)

return 0


@register.simple_tag
def is_multiple_filter_choice(spec):
not_multiple = []
if hasattr(spec, 'field_generic'):
if spec.field_generic.endswith('__'):
return ''

return 'multiple'
Loading

0 comments on commit a499b6f

Please sign in to comment.