我正在使用 ngx-translate 模块制作一个 angular2 应用程序
该服务使用 .json 文档来查找翻译
首先...我注意到本地 json 文档路径是“/src/assets/i18n/”,如下图所示:
因此,翻译服务使用默认语言来翻译不同的文本
这就是我的 app.component.ts 的工作原理:
import { Component, OnInit, AfterContentInit } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
@Component({
selector: 'app-root',
template: '<router-outlet></router-outlet>'
})
export class AppComponent implements OnInit {
constructor(translate: TranslateService) {
translate.addLangs(['es']);
translate.setDefaultLang('es');
const browserLang: string = translate.getBrowserLang();
translate.use(browserLang.match(/en|es/) ? browserLang : 'es');
}
ngOnInit() {
}
}
Run Code Online (Sandbox Code Playgroud)
因此该服务使用“en.json”、“es.json”和“fr.json”来匹配翻译。
所以我的问题是
如何避免“json”文档并将文本与数据库中的文本匹配?
所以客户端永远不必重建以获得新的翻译更新,只需添加到数据库并自动翻译而无需重建
我正在 Angular 2 v4 Web 应用程序中工作,我需要使用从 REST 获取的数组数据生成一个 KML 文件。我的 REST 的响应是这样的:
[
{ "lat": 14.05891566, "lng": -19.9981566 },
{ "lat": 14.05668566, "lng": -19.9566123 },
{ "lat": 14.05567413, "lng": -19.9467456 },
{ "lat": 14.05455655, "lng": -19.9367125 }
...
]
Run Code Online (Sandbox Code Playgroud)
REST 只是响应坐标数组
如何使用该数据生成 KML 文件,然后下载文件 .kml?
如果可能的话,我正在寻找一个允许我执行此操作的节点模块,但如果它不存在,那么正确的方法是什么?
我的应用程序需要在静态文件夹内的不同文件夹中上传不同的配置文件图像。还有一件事,我没有使用模型,我只想拍摄我在html输入文件中选择的图片并将其复制到特定文件夹。
这是我的文件夹树。我要保存上传的图像MYPROJECTFOLDER/static/profile/<TheUserSpecificFolder>/的位置是我不想使用的位置MEDIA_ROOT,因为在媒体根目录中,我无法为每个用户创建一个特定的文件夹。(我不知道这是否正确,是否可以在/ media /文件夹中为每个用户创建一个特定的文件夹而不使用ImageField或FileField,请告诉我)。
这是我的文件夹树:
MYPROJECTFOLDER
|
|------myproject/
|
|------myapp/
|
|------static
| |-------profile
| |------folder_user1
| |------ uploadedpicture.jpg #Here is where I want to upload
| |------folder_user2
Run Code Online (Sandbox Code Playgroud)
这是我的 uploadpic.html
<form action="{% url 'upload' %}" enctype="multipart/form-data" method="POST">
{% csrf_token %}
<input type="file" name="avatar" accept="image/gif, image/jpeg, image/png">
<button type="submit">Upload</button>
</form>
Run Code Online (Sandbox Code Playgroud)
这是我的views.py
from django.shortcuts import render, HttpResponse, redirect
from . import forms
import os
def upload(request):
img = request.FILES['avatar']
#This just create the …Run Code Online (Sandbox Code Playgroud) I got a serie of html in my server. For example:
And I trying to include those files into a<div> in my angular2 v4 app. For example:
component.ts
public changePage(name: string) {
switch (name) {
case 'intro': this.myHtmlTemplate = 'http://docs.example.com/intro.html'; break;
case 'page1': this.myHtmlTemplate = 'http://docs.example.com/page1.html'; break;
case 'page2': this.myHtmlTemplate = 'http://docs.example.com/page2.html'; break;
}
}
Run Code Online (Sandbox Code Playgroud)
component.html
<div [innerHtml]="myHtmlTemplate"></div>
Run Code Online (Sandbox Code Playgroud)
but it doesnt work. I tried the following solutions:
我正在 Angular 4 应用程序中工作,一切正常,直到我克隆我的存储库并运行 npm install 和 ngserve
这个错误似乎是问题所在
ERROR in C:/Users/mypcuser/Desktop/myproject/node_modules/moment-timezone/index.d.ts (47,77): ';' expected.
ERROR in C:/Users/mypcuser/Desktop/myproject/node_modules/moment-timezone/index.d.ts (47,92): ';' expected.
ERROR in C:/Users/mypcuser/Desktop/myproject/node_modules/moment-timezone/index.d.ts (47,111): ';' expected.
ERROR in C:/Users/mypcuser/Desktop/myproject/node_modules/moment-timezone/index.d.ts (48,27): ';' expected.
ERROR in C:/Users/mypcuser/Desktop/myproject/node_modules/moment-timezone/index.d.ts (48,49): ')' expected.
ERROR in C:/Users/mypcuser/Desktop/myproject/node_modules/moment-timezone/index.d.ts (48,71): Expression expected.
ERROR in C:/Users/mypcuser/Desktop/myproject/node_modules/moment-timezone/index.d.ts (48,74): ';' expected.
ERROR in C:/Users/mypcuser/Desktop/myproject/node_modules/moment-timezone/index.d.ts (48,75): Declaration or statement expected.
ERROR in C:/Users/mypcuser/Desktop/myproject/node_modules/moment-timezone/index.d.ts (48,79): ';' expected.
ERROR in C:/Users/mypcuser/Desktop/myproject/node_modules/moment-timezone/index.d.ts (49,32): ',' expected.
ERROR in C:/Users/mypcuser/Desktop/myproject/node_modules/moment-timezone/index.d.ts (49,54): Expression expected.
ERROR in C:/Users/mypcuser/Desktop/myproject/node_modules/moment-timezone/index.d.ts …Run Code Online (Sandbox Code Playgroud) 我正在使用 ExpressJS 和 Mongo 处理 REST api,并且我有一个包含 N 个级别的集合。
所以为了解决这个问题,我在 mongo 中使用了一个递归表(或集合),其中一个字段是 id,每个寄存器都有一个 parent_id,它与它的孩子处于同一级别。为了更好地解释这一点,这里是一个 ER 表示
因此,正如您所见,mongo 会像这样保存数据 json(帐户级别 0 的父级为 null)
[
{ "id": "45TYYU", "parent_id": null, "name":"account 1", "type": 1, "category": 1 },
{ "id": "45TYYXT", "parent_id": "45TYYU", "name":"account 2", "type": 1, "category": 1 },
{ "id": "45TYYPZ", "parent_id": "45TYYU", "name":"account 3", "type": 1, "category": 1 },
{ "id": "45TYYPZRE", "parent_id": "45TYYPZ", "name":"account 4", "type": 1, "category": 1 },
{ "id": "45TYYPZSX", "parent_id": "45TYYPZ", "name":"account 5", "type": 1, …Run Code Online (Sandbox Code Playgroud) 我需要将日期转换为 int 以与模板中的其他值进行比较。
像这样的东西:
视图.py
def userEdit(request):
userdata = user.objects.get(id=request.session['user_id'])
dic.update({'userdata':userdata, 'dayrange': range(1,32)})
return render(request, 'my_app/userEdit.html', dic)
Run Code Online (Sandbox Code Playgroud)
my_app/userEdit.html
<select name="day">
{% for i in dayrange %}
{% if i == userdata.birth_date|date:"d" %}
<option value="{{ i }}" selected>{{ i }}</option>
{% else %}
<option value="{{ i }}">{{ i }}</option>
{% endif %}
{% endfor %}
</select>
Run Code Online (Sandbox Code Playgroud)
我需要将 userdata.birth_date|date:"d" 转换为 int 然后与 for 循环中的 "i" 变量进行比较。请帮忙
事情就是这样......我在我的应用程序中使用了一个 angular 4 模板,它有一个很好的工作翻译服务。问题是我不知道如何在代码中使用该管道。
在 HTML 中<span>{{ this.variable | traslate }}</span>,然后,该服务会转到一些 JSON 文件以查找文本并进行翻译。
这是我的 component.ts 中的代码
const SMALL_WIDTH_BREAKPOINT = 960;
@Component({
selector: 'app-mycomponent',
templateUrl: './mycomponent.component.html',
styleUrls: ['./mycomponent.component.scss']
})
export class TrackingComponent implements OnInit {
currentLang = 'es';
private mediaMatcher: MediaQueryList = matchMedia(`(max-width:
${SMALL_WIDTH_BREAKPOINT}px)`);
constructor(
public translate: TranslateService,
zone: NgZone,
private router: Router,
) {
const browserLang: string = translate.getBrowserLang();
translate.use(browserLang.match(/en|es/) ? browserLang : 'es');
this.mediaMatcher.addListener(mql => zone.run(() => {
this.mediaMatcher = mql;
}));
translate.use(this.currentLang);
}
ngOnInit() { } …Run Code Online (Sandbox Code Playgroud)