gpt4 book ai didi

python - Django 模板本地化错误

转载 作者:行者123 更新时间:2023-11-30 23:31:02 25 4
gpt4 key购买 nike

我在本地化方面遇到问题。我的网站有英语和俄语区域设置。从一开始,标签“Home”就被翻译成俄语,但我没有添加 django.po 文件,但现在我添加和翻译不起作用。

来自 django.po 的部分,如你所见,我没有更改“Home”标签,但它翻译了......

#: templates/base.html:7 templates/base.html.py:96 templates/login.html:15
msgid "Friends on Map"
msgstr "Друзья на карте"

#: templates/base.html:100 templates/login.html:10
msgid "Home"
msgstr ""

我尝试将文件夹“本地”添加到不同的项目文件夹,但没有帮助。

图片如所见

https://www.dropbox.com/s/q06tvioz849dy19/Screenshot%20from%202013-11-26%2003%3A30%3A09.png

以及项目结构

https://www.dropbox.com/s/fa0d2iry41m8coh/Screenshot%20from%202013-11-26%2003%3A35%3A09.png

更新 01.12这是我的base.html:

{% load static %}
{% load i18n %}
<!Doctype html>
<html xmlns="http://www.w3.org/1999/html">
<head>
<meta charset="utf-8">
<title>{% trans "Friends on Map" %}</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="/static/css/bootstrap.min.css" rel="stylesheet" media="screen">
<link href="/static/css/style.css" rel="stylesheet" media="screen">
<script language="JavaScript" src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" type="text/javascript"></script>
{% block mapJS %}
<script type="text/javascript"
src="https://maps.googleapis.com/maps/api/js?key=key&sensor=false">
</script>
<script type="text/javascript">
google.maps.visualRefresh = true;
var map;
function initialize() {

var mapOptions = {
zoom: 3,
center: new google.maps.LatLng(0,0),
mapTypeId: google.maps.MapTypeId.TERRAIN
};

map = new google.maps.Map(document.getElementById('map-canvas'),
mapOptions);

{% if backends.associated %}
var myLatlng = new google.maps.LatLng({{ user_model.extra_data.user_info.current_location.latitude }},
{{ user_model.extra_data.user_info.current_location.longitude }}
);

addMarker("{{ user_model.extra_data.user_info.current_location.latitude }}",
"{{ user_model.extra_data.user_info.current_location.longitude }}",
"{{ user_model.extra_data.user_info.name }}",
"{{ user_model.extra_data.user_info.current_location.name }}",
"{{ user_model.extra_data.user_info.pic_big }}");

var json1 = {{ friends|safe }};
$.each(json1, function(key, data){
addMarker(data.current_location.latitude,
data.current_location.longitude,
data.name,
data.current_location.name,
data.pic_square);
console.log(data.name);
});
{% endif %}
}

function addMarker(lat,lng,name,address,photo) {

var contentString = '<div id="content">'+
'<div id="siteNotice">'+
'</div>'+
'<p>'+ name +'</p>'+
'<div id="bodyContent">'+
'<img src="'+ photo +'">'+
'<p>'+ address +'</p>'+
{# '<href="'+ url+ '">'+#}
'</div>'+
'</div>';

var Marker = new google.maps.Marker({
position: new google.maps.LatLng(lat,lng),
title: name,
});

var infowindow = new google.maps.InfoWindow({
content: contentString
});

google.maps.event.addListener(Marker, 'click', function() {
infowindow.open(map,this);

});

Marker.setMap(map);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
{% endblock %}
{# {% block scripts %}{% endblock %}#}
{% block head_scripts %}{% endblock %}
</head>

<body>
<div class="navbar navbar-fixed-top navbar-inverse" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/login">{% trans "Friends on Map" %}</a>
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li class="active"><a href="/login">{% trans "Home" %}</a></li>
<li><a href="/about">{% trans "About" %}</a></li>
</ul>
<ul class="nav navbar-right"><!-- Set language start -->
<form action="/i18n/setlang/" class="active" method="post">
{% csrf_token %}
<input name="next" type="hidden" value="{{ redirect_to }}" />
{% get_language_info_list for LANGUAGES as languages %}
{% for language in languages %}
<input name="language" type="submit" value="{{ language.code }}"/>
{% endfor %}
</form>
</ul><!-- Set language end-->
</div><!-- /.nav-collapse -->
</div><!-- /.container -->
</div><!-- /.navbar -->

<div class="container">

<div class="row row-offcanvas row-offcanvas-right">

<div class="col-xs-12 col-sm-9">
<div class="jumbotron">
{% block content %}
<div id="map-canvas"></div>
</div>
{% endblock %}
</div>

<div class="col-xs-6 col-sm-3 sidebar-offcanvas" id="sidebar" role="navigation">
<div class="well sidebar-nav">
<div class="list-group">
{% block sidebar %}{% endblock %}
</div>
</div><!--/span-->
</div>




<form method="post" action="" id="disconnect-form">{% csrf_token %}</form>
<script src="/static/js/bootstrap.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$(document).on('click', 'a.disconnect', function (e) {
e.preventDefault();
$('form#disconnect-form')
.attr('action', $(this).attr('href'))
.submit();
});
});
</script>

</body>
</html>

最佳答案

Django 有多种语言的内置翻译,并且可以翻译许多关键字。查看可能的解决方案:How do I disable default translation values in Django?

关于python - Django 模板本地化错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20206959/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com