我有 TYPO3 V7.6.18 构建的多语言网站。它使用的口号应保持可编辑但三种语言不同。这是一个在流体模板中硬编码的变量。
对于这种变量,我使用文件from random import randint
board = []
for x in range(5):
board.append(["O"] * 5)
def print_board(board):
for row in board:
print " ".join(row)
print "Let's play Battleship!"
print_board(board)
def random_row(board):
return randint(0, len(board) - 1)
def random_col(board):
return randint(0, len(board[0]) - 1)
ship_row = random_row(board)
ship_col = random_col(board)
print ship_row
print ship_col
turn = 1
for turn in range(4):
print turn
guess_row = int(raw_input("Guess Row:"))
guess_col = int(raw_input("Guess Col:"))
if guess_row == ship_row and guess_col == ship_col:
print "Congratulations! You sunk my battleship!"
break
else:
if (guess_row < 0 or guess_row > 4) or (guess_col < 0 or guess_col > 4):
print "Oops, that's not even in the ocean."
elif(board[guess_row][guess_col] == "X"):
print "You guessed that one already."
else:
print "You missed my battleship!"
board[guess_row][guess_col] = "X"
print turn + 1
print_board(board)
if turn == 3:
print "Game Over"
来定义可编辑的变量(Configuration/TypoScript/constants.ts
)并使用:
WEB -> Template -> Constant Editor
然后我将#---------------------------------------------------------------------
# constants.ts
#---------------------------------------------------------------------
# customsubcategory=general=General Setup
myextension.configuration {
general {
# cat=myextension/general/05; type=string; label=Website Slogan.
slogan= website slogan in main language
}
}
[globalVar = GP:L=1]
myextension.configuration.general.slogan = website slogan in second language
[end]
[globalVar = GP:L=2]
myextension.configuration.general.slogan = website slogan in third language
[end]
中的变量绑定起来使用:
Configuration/TypoScript/setup.ts
此代码有效,但只有主要语言的口号可编辑...
任何使口号可以用其他两种语言编辑的解决方案吗?
答案 0 :(得分:3)
有三种可能性,其中两种是Mathias和Riccardo提到的。我将添加第三个列表的优缺点。
所以,首先是第三种可能性,即创建一个内容元素(最好是类型header
)并创建一个保持其uid
的TypoScript常量。
# cat=myextension/general/05; type=int; label=Slogan CE UID
myextension.configuration.general.sloganUid =
然后在流体变量中获取此内容元素的标题:
page.10.variables.slogan = CONTENT
page.10.variables.slogan {
select.uidInList = {$myextension.configuration.general.sloganUid}
table = tt_content
renderObj = TEXT
renderObj.field = header
}
创建一个sysfolder,创建一个header类型的内容元素,并在你的常量中检测它的uid。也许你需要在.select
添加一些东西才能使它工作 - 我总是不确定。
现在有利有弊:
答案 1 :(得分:2)
我建议使用常量的语言标识符:
myextension.configuration {
general {
slogan {
# cat=myextension/general/05; type=string; label=Website Slogan in default language.
default = website slogan in main language
# cat=myextension/general/06; type=string; label=Website Slogan in second language.
second = website slogan in second language
# cat=myextension/general/07; type=string; label=Website Slogan in third language.
third = website slogan in third language
}
}
}
然后将条件移至设置:
page = PAGE
page {
# Page Main template
10 = FLUIDTEMPLATE
10 {
variables {
# slogan
slogan = TEXT
slogan.value = {$myextension.configuration.general.slogan.default}
}
}
}
[globalVar = GP:L=1]
page.10.variables.slogan.value = {$myextension.configuration.general.slogan.second}
[end]
[globalVar = GP:L=2]
page.10.variables.slogan.value = {$myextension.configuration.general.slogan.third}
[end]